GSP 115 DeVry Week 3 Assignment Latest

admin   June 30, 2017   Comments Off on GSP 115 DeVry Week 3 Assignment Latest

GSP 115 DeVry Week 3 Assignment Latest

Downloading is very simple, you can download this Course here:

http://wiseamerican.us/product/gsp-115-devry-week-3-assignment-latest/

Or

Contact us at:

SUPPORT@WISEAMERICAN.US

GSP 115 DeVry Week 3 Assignment Latest

GSP115

GSP 115 DeVry Week 3 Assignment Latest

GSP 115 DeVry Week 3 Assignment Latest

Loops and Branching

Instructions

Complete the following assignments. Copy and paste your finished code into a Word document, clearly identifying which assignment it is. Also, capture the output of the program and paste that into the Word document. If there are questions to be answered, put the answers after the output. When you complete all three of this week’s assignments, save the document as yourLastName_GSP115_W3_Assignments.docx.Submit it to the Week 3 assignment Dropbox.

  1. Compile Time Bugs

Find and fix the fivecompile time bugs in the code at the end of this section. Compile time bugs show as errors when you compile, but the Visual Studio IDE also gives you visual clues in the form of red squiggly underlines, as shown here.jpg”>. You will actually see more than five errors, but they are all caused by just five bugs (four in just one line). Remember, start with the first error in your code and work down.

Here is the code.

// Week 1 Assignment-1

// Description: Compile time errors with loops and branching

//———————————-

//**begin #include files************

#include// provides access to cin and cout

#include// to allow seeding the random number generator using time

//–end of #include files———–

//———————————-

usingnamespacestd;

//———————————-

//**begin global constants**********

constintarraySize = 5;

//–end of global constants———

//———————————-

//**begin main program**************

int main()

{ // seed random number generator

srand(time(NULL));

// create a flag to end the while loop

boolendLoop =false;

// create an

int array int array[arraySize];

// initialize the int array

for (i = 0;

{ array[i] = (rand()%50) + 50; }

int number;

intmysteryNum;

intarrayNum;

while (!endLoop)

{

mysteryNum = rand()%40;

arrayNum = array[rand()%arraySize];

cout<<” What number do you need to subtract from “<> number;

if (mysteryNum == arrayNum – number)

{ cout<<“You got the number!”<

else

{ cout<<“That’s not the right number.”<

endLoop =true; } }

cin.get();

// Wait for user input to close program when debugging.

cin.get();

return 0; }

//–end of main program————-

//———————————-

  1. Run-Time Errors in Loops and Branching

Loops and branching are hot spots for simple but difficult-to-spot bugs. This code is filled with some very annoying and common bugs. The code will compile fine, but it won’t work right and may even crash.There are two bugs that are crash bugs. There is one logic error that causes the program to quit before it should and one typo that causes incorrect behavior. This last one will be the hardest to find because it only happens when you win, and it is an error that is notoriously hard to spot until you’ve been caught by it enough to expect it.

This is a simple slot machine. Here is how it is supposed to work.

  1. When you hit the return key, the wheel spins (you won’t actually see any spinning, just the results of the spin).
  2. You automatically bet $1 on each spin.
  3. If you get three of the same symbols, you win according to the following table.
  4. Lemons—you keep your bet.
  5. Cherries—you win $5.
  6. Oranges—you win $10.
  7. Bells—you win $15.
  8. Jackpot—you win $1,000 and the game is over.
  9. When your pot is gone (pot == 0), you lose and the game is over.

Here is the code.

// Week 3 Assignment- 2

// Description: Run-time errors in loops and branching

//———————————-

//**begin #include files************

#include// provides access to cin and cout

#include

//–end of #include files———–

//———————————-

usingnamespacestd;

//———————————-

//**begin main program**************

int main()

{ // seed random number generator

srand(time(NULL));

// create enum for symbols

enumsymbol

{ Lemon,Cherry,Orange,Bell,Jackpot };

// create a struct for slot machine wheel

structWheel

{ array symbols; arrayeSymbols; int position; string selected; };

//create an array of three slot machine wheels

arrayslotMachine = { { { {“Cherry”,”Orange”,”Lemon”,”Orange”,”Bell”,”Orange”,”Lemon”,”Cherry”,”Jackpot”,”Bell”},

{Cherry,Orange,Lemon,Orange,Bell,Orange,Lemon,Cherry,Jackpot,Bell},

0,”Cherry”

}, {

{“Cherry”,”Bell”,”Lemon”,”Orange”,”Bell”,”Jackpot”,”Lemon”,”Cherry”,”Jackpot”,”Bell”},

{Cherry,Bell,Lemon,Orange,Bell,Jackpot,Lemon,Cherry,Jackpot,Bell},

1,”Bell” }, {

{“Cherry”,”Orange”,”Lemon”,”Orange”,”Lemon”,”Orange”,”Lemon”,”Cherry”,”Jackpot”,”Bell”},

{Cherry,Orange,Lemon,Orange,Lemon,Orange,Lemon,Cherry,Jackpot,Bell},

2,”Lemon” } } };

boolgameOn =true;

bool winner =false;

intthePot = 100;

int bet = 1;

vector combo;

while (gameOn)

{ for (inti = 1; i< 4; i++)

{ slotMachine[i].position =(slotMachine[i].position + rand());

slotMachine[i].selected = slotMachine[i].symbols[slotMachine[i].position];

cout< 0

}

if ((combo[0] == combo[1]) && (combo[1] == combo[2]))

{ if (combo[0] ==Lemon)

{ cout<<“You keep your bet.”< 0 )

{ cout<<“**** You hit $1000 Jackpot!!! ****”<

thePot += 1000;

winner =true;

gameOn =false; } else

{

cout<<“WINNER! You win $”

combo.clear();

cout<

} if (winner) cout<<“You walk away a winner.”<

elsecout<<“You have lost all your money.”<

// Wait for user input to close program when debugging.

cin.get();

return 0; }

//–end of main program————-

//———————————-

 

  1. Create a Program FromPseudocode

This exercise will be to use pseudocode (in the form of comments) to write a program that simulates a one-sided snowball fight. You select the row and column you want the snowball to hit; if the target is at that location, you get a point; otherwise, you get the distance (but not the direction) of the target from the snowball hit point. The distance is calculated by taking the absolute value of the difference between the x position of the target and the snowball hit and the y position and the snowball hit. Report the larger of the two if they are different.

After each throw of the snowball, the target moves using the following algorithm.

Generate a random number (0–2). The target doesn’t move if the random number is 0. If the random number is 1, the target changes its x position. If the random number is 2, it changes its y position. Randomly choose whether to increment by one or decrement by one. If the target is on the boundary of the grid, move away from the boundary by one.

The grid size should be 5.

The number of turns should be 10.

Here is the pseudocode.

// Week 3 Assignment-3

// Description: Snowball fight – version 1

//———————————-

//**begin #include files************

#include// provides access to cin and cout

//–end of #include files———–

//———————————-

usingnamespacestd;

//———————————-

//**begin global constants**********

// define a struct of the target

// — xPos is the x position (the column)

// — yPos is the y position (the row)

// — xHit is x position of the hit(the column)

// — yHit is y position of the hit(the row)

// — distance between target and snowball hit

// — hits is how many times the target has been hit

// const grid size (i.e. 5×5 grid constant is 5)

// const number of turns

//–end of global constants———

//———————————-

//**begin main program**************

int main()

{

// initialization

// seed the random number generator

// create the target struct

// set target at random location

// set hits to zero

// loop for the specified number of turns

// get x and y position for the snowball from player

// compare to the target’s position

// report hit, or distance of miss (see instructions for details)

// target moves (see instruction for details)

// end of loop

// report score (number of hits vs turns)

// Wait for user input to close program when debugging.

cin.get();

return 0; }

}

//–end of main program————-

//———————————-