SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 04 Dec 2017 My Price 8.00

two lines that create the arrays and initialize them to 0.

I need help with these questions and I only have $40. I hope you can help me...

 

This is the code and this is what I don't understand how to do.......□    to fill in the two lines that create the arrays and initialize them to 0.

 

#include <iostream> // gives us access to cout and cin

#include <time.h> // needed to access time for the random number seed.

                    

using namespace std;// Without this, we would have to use std:: with cout, cin, and endl. (e.g std::cout)

 

//***---Week 2 iLab Part A: Working with Arrays---***

 

int main()

{

      // Create two initialized variables for an array of 10 ints

      // ADD YOUR CODE HERE

      // Generate a random number seed

      srand(time(0));

      // variables to save the left and right wins

      int leftCount = 0;

      int rightCount = 0;

      // Use a for loop to get random numbers (1-8) into the array

      // (we'll cover the for loop next week)

      for (int index = 0; index < 10; index++)

      {     

             left[index] = rand()%8 + 1; // Store random number in left

             right[index] = rand()%8 + 1;// Store random number in right

      }

      cout << "Let the battle begin!" << endl;

      for (int index = 0; index < 10; index++)

      {

             bool leftWin = false;

             bool rightWin = false;

             cout << "left[" << index << "] = " << left[index] << " right[" << index << "] = " << right[index] << endl;            

             int sum = left[index] + right[index]; //add the two values

             if (sum > 8)

             {

                    leftCount++;

                    leftWin = true;

             }

             if (sum%2 == 0)

             {

                    rightCount++;

                    rightWin = true;

             }

             if (leftWin && rightWin)

             {

                    cout << "Both win, so round "<< index << " is a tie." << endl;

             }

             else if (leftWin)

             {

                    cout << "Left wins round " << index << "!" << endl;

             }

             else if (rightWin)

             {

                    cout << "Right wins round " << index << "!" << endl;

             }

             else cout << "No winner for round " << index << "." << endl;

             cout << endl;

      }

      cout << "Left won " << leftCount << endl << "Right won " << rightCount << endl;

      // you need to add this line to see the output if you are running in debug mode.

      cin.get();

return 0;

}

 

 

PART B

 

 

#include <iostream>

#include <cstring>

#include <string>

#include <time.h>

 

using namespace std;

 

int main()

{

      // create three arrays of two strings--

      string sArray1[] ={"Hello, ","Hi there, ","What's up, "};

      //// YOUR CODE HERE: create two more string arrays

      //// seed the random number generator

      srand(time(0));

      // Generate three sentences

      for (int i = 0; i < 3; i++)

      {

             cout << sArray1[rand()%3] << sArray2[rand()%3] << sArray3[rand()%2] << endl;

      }

      cout << endl;

      cin.get();

      return 0;

}

 

After you have added the additional two string arrays—sArray2 and sArray3—build and run the code. If it runs without bugs. Increase the number of strings in each array to 5 and increase the number of times the program runs by changing “i < 3” to “i < 5” in the for loop. You will also need to change the “rand()%3” to “rand()%5” in the coutstatement.

 

PART C

 

#include <iostream>

#include <cstring>

#include <string>

#include <time.h>

 

using namespace std;

 

int main()

{

//Create an enumeration

enum Weapons

{

Sword, Bow, Axe, Spear, Nuclear_Weapon

};

// Create a struct

struct character

{

string name;

int health, strength, charisma;

string weapon;

float wealth;

};

// Create a struct variable

character myCharacter1;

// seed the random number generator

// Create an array of strings

srand(time(0));

// get my characters's information

cout << "What is your character's name? ";

getline(cin, myCharacter1.name);

cout << "What is " << myCharacter1.name << "'s weapon? ";

getline(cin, myCharacter1.weapon);

myCharacter1.health = rand() % 20 + 80;

myCharacter1.strength = rand() % 80 + 20;

myCharacter1.charisma = rand() % 100;

myCharacter1.wealth = float(rand() % 3000) / 100.0f;

cout << myCharacter1.name << " has the following attributes:" << endl;

cout << "Health is " << myCharacter1.health << endl;

cout << "Strength is " << myCharacter1.strength << endl;

cout << "Charisma is " << myCharacter1.charisma << endl;

cout << "Weapon is " << weaponNames[myCharacter1.weapon] << endl; -----------------------------------------(THIS IS THE PART THAT I CANT FIX AND I DONT UNDERSTAND WHY)

cout << "Wealth is " << myCharacter1.wealth << endl;

cout << endl;

cin.get();

return 0;

}

 

 

Thanks!

Answers

(5)
Status NEW Posted 04 Dec 2017 02:12 PM My Price 8.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)