SlideShare a Scribd company logo
1 of 29
Download to read offline
DeVry GSP 115 Week 3 Assignment latest
Just Click on Below Link to Download This Course:
https://www.devrycoursehelp.com/product/devry-gsp-115-week-3-assignment-latest/
Or
Email us
help@devrycoursehelp.com
DeVry GSP 115 Week 3 Assignment latest
Week 3: 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. 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<iostream>// provides access to cin and cout
#include<time.h>// 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; i<arraysize: i++);
{
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 “<<arrayNum<<” to get “<<mysteryNum<<“? “;
cin>> number;
if (mysteryNum == arrayNum – number)
{
cout<<“You got the number!”<<endl;
else
{
cout<<“That’s not the right number.”<<endl;
endLoop =true;
}
}
cin.get();
// Wait for user input to close program when debugging.
cin.get();
return 0;
}
//–end of main program————-
//———————————-
2. 2.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. 1.When you hit the return key, the wheel spins (you won’t actually see any spinning, just the results of the spin).
2. 2.You automatically bet $1 on each spin.
3. 3.If you get three of the same symbols, you win according to the following table.
4. a.Lemons—you keep your bet.
5. b.Cherries—you win $5.
6. c.Oranges—you win $10.
7. d.Bells—you win $15.
8. e.Jackpot—you win $1,000 and the game is over.
9. 4.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<iostream>// provides access to cin and cout
#include<iomanip>
#include<array>
#include<vector>
//–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<string, 10> symbols;
array<symbol, 10>eSymbols;
int position;
string selected;
};
//create an array of three slot machine wheels
array<Wheel, 3>slotMachine =
{
{
{
{“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<int> 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<<setw(10) << left <<slotMachine[i].selected.c_str() ;
combo.push_back(slotMachine[i].eSymbols[slotMachine[i].position]);
}
if ((combo[0] == combo[1]) && (combo[1] == combo[2]))
{
if (combo[0] ==Lemon)
{
cout<<“You keep your bet.”<<endl;
}
elseif(combo[0] =Jackpot)
{
cout<<“**** You hit $1000 Jackpot!!! ****”<<endl;
thePot += 1000;
winner =true;
gameOn =false;
}
else
{
cout<<“WINNER! You win $”<<combo[0]*5 <<endl;
thePot += combo[0]*5;
}
}
else
{
thePot -= bet;
if (thePot> 0 ) gameOn=false;
}
cout<<“You now have $”<<thePot<<endl;
combo.clear();
cout<<endl;
cin.get();
}
if (winner) cout<<“You walk away a winner.”<<endl;
elsecout<<“You have lost all your money.”<<endl;
// Wait for user input to close program when debugging.
cin.get();
return 0;
}
//–end of main program————-
//———————————-
3. 3.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<iostream>// 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————-
//———————————-
DeVry GSP 115 Week 4 Assignment latest
Week 4: More 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_W4_Assignments.docx.Submit it to the Week 4 assignment Dropbox.
1. 1.Compile Time Bugs
Find and fix the compile 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”>. This assignment is meant to test
your attention to detail and strengthen your debugging skills.
Here is the code.
// Week 4 Assignment-1
// Description: Compile time errors
//———————————-
//**begin #include files************
#include<iostream>// provides access to cin and cout
#include<fstream>// provides access to file commands
#include<string>// provides access to string commands
#include<vectors>// provides access to std::vector
//–end of #include files———–
//———————————-
usingnamespacestd;
//———————————-
//**begin global constants**********
//–end of global constants———
//———————————-
//**begin main program**************
int main()
{
// create and initialize variables
stringmyTextString;
stringmyFilename;
vector<string>myStrVector;
ifstreaminFile;
ofstreamoutFile;
cout<<“enter a file name (without an extension): “<<endl;
getline(cin, myFilename);
myFilename +=”.txt”;
// open an output file
outfile.open(myFilename);
// write to a file
for(inti = 0; i< 3;i++)
{
cout>>”enter a line of text: “;
getline(cin, myTextString);
outFile<<myTextString<<endl;
}
// close the file
outFile.close();
// open an input file
inFile.open(myFilename);
// read from the file
while (getline(inFile,myTextString))
{
myStrVector.push_back(myTextString);
}
inFile.close();
// use a range-based for loop with a switch statement
for(auto s: myStrVector)
{
cout<< s <<endl;
charswitchFlag = s[0];
switch (switchFlag)
{
case”a”:
cout<<“Hey, a vowel. The ‘a’ vowel actually.”<<endl;
break;
case’e’:
cout<<“See vowel. See vowel run. run vowel, run. The ‘e’ vowel.”<<endl;
break;
case’i’:
cout<<“I know. It’s a vowel. The ‘i’ vowel.”<<endl;
break;
case’o’:
cout<<“Oh! Don’t you know, it’s the ‘o’ vowel.”<<endl;
break;
case’u’:
cout<<“Whew! We got a you. Actually, the ‘u’ vowel.”<<endl;
break;
case’s’:
cout<<“Oh great! I love ‘s’s. More ‘s’s, please.”<<endl;
break;
default
cout<<“Nothing interesting here. I would really like to see an ‘s’.”<<endl;
break;
}
}
// Wait for user input to close program when debugging.
cin.get();
return 0;
}
//–end of main program————-
//———————————-
2. 2.Run-Time Errors
We revisit the slot machine from last week, this time using a range-based For loop and the Switch statement. The Switch gives us some
flexibility in coding the payouts. The code has one compile time bug and two run-time bugs. One of the run-time errors is a typo and the
other is a logic error.Fix the compile error and run the program to find the run-time errors. Neither run-time bug will show up right away.
This is to give you experience with testing your program to make sure it works. Often, although a program seems to be OK, it isn’t. Hint:
Look for occasional erroneous wins of $1 when the first symbol is Bar.
Here is the code.
// Week 4 Assignment- 2
// Description: Run-time errors in more loops and branching
//———————————-
//**begin #include files************
#include<iostream>// provides access to cin and cout
#include<iomanip>
#include<array>
#include<vector>
//–end of #include files———–
//———————————-
usingnamespacestd;
//———————————-
//**begin global constants**********
// number of positions on a reel (11)
constintreelPositions = 11;
//–end of global constants———
//———————————-
//**begin main program**************
int main()
{
// seed random number generator
srand(time(NULL));
// create enum for symbols
enum symbol
{
Lemon, Cherry, Orange, Bell, Bar, Jackpot
};
// create a struct for slot machine wheel
struct Wheel
{
array<string, reelPositions> symbols;
array<symbol, 1reelPositions1>eSymbols;
int position;
string selected;
};
//create an array of three slot machine wheels
array<Wheel, 3>slotMachine =
{
{
{
{“Bar”,”Orange”,”Lemon”,”Orange”,”Bell”,”Orange”,”Bar”,”Lemon”,”Bell”,”Jackpot”,”Bell”},
{Bar, Orange, Lemon, Orange, Bell, Orange, Lemon, Bell, Jackpot, Bell},
0,”Cherry”
},
{
{“Lemon”,”Bell”,”Lemon”,”Orange”,”Bell”,”Jackpot”,”Bar”,”Lemon”,”Cherry”,”Jackpot”,”Bell”},
{Lemon, Bell, Lemon, Orange, Bell, Jackpot, Bar, Lemon, Cherry, Jackpot, Bell},
1,”Bell”
},
{
{“Cherry”,”Orange”,”Bar”,”Lemon”,”Orange”,”Lemon”,”Orange”,”Lemon”,”Cherry”,”Jackpot”,”Bell”},
{Cherry, Orange, Bar, Lemon, Orange, Lemon, Orange, Lemon, Cherry, Jackpot, Bell},
2,”Lemon”
}
}
};
boolgameOn =true;
intthePot = 100;
int bet = 1;
bool winner =false;
int winnings = 0;
charcheckKey =’n’;
vector<int> combo;
cout<<“Hit return to bet, space and return to quit.”<<endl;
while (gameOn)
{
for (auto s: slotMachine)
{
s.position=(s.position + rand()%reelPositions)%reelPositions;
s.selected = s.symbols[s.position];
cout<<setw(10) << left <<s.selected.c_str() ;
combo.push_back(s.eSymbols[s.position]);
}
winnings = -bet;
switch (combo[0]);
{
case Lemon:
switch (combo[1])
{
case Lemon:
if (combo[2] == Lemon) winnings = 1;
elseif (combo[2] == Cherry) winnings = 1;
break;
case Cherry:
winnings = 1;
if (combo[2] == Cherry) winnings = rand()%4+2;
break;
default:
if (combo[2] == Cherry) winnings = 1;
break;
}
break;
case Cherry:
winnings = 1;
if ((combo[1] == Cherry) && (combo[2] == Cherry)) winnings = 10;
elseif ((combo[1] == Cherry) || (combo[2] == Cherry)) winnings = rand()%4+2;
break;
case Orange:
switch (combo[1])
{
case Orange:
if (combo[2] == Orange) winnings = 15;
elseif (combo[2] == Cherry) winnings = 1;
break;
case Cherry:
winnings = 1;
if (combo[2] == Cherry) winnings = rand()%4+2;
break;
default:
if (combo[2] == Cherry) winnings = 1;
break;
}
break;
case Bell:
switch (combo[1])
{
case Bell:
if (combo[2] == Bell) winnings = 20;
elseif (combo[2] == Cherry) winnings = 1;
break;
case Cherry:
winnings = 1;
if (combo[2] == Cherry) winnings = rand()%4+2;
break;
default:
if (combo[2] = Cherry) winnings = 1;
break;
}
break;
case Bar:
switch (combo[1])
{
case Bar:
if (combo[2] == Bar) winnings = 40;
elseif (combo[2] == Cherry) winnings = 1;
break;
case Cherry:
winnings = 1;
if (combo[2] == Cherry) winnings = rand()%4+2;
break;
default:
if (combo[2] == Cherry) winnings = 1;
break;
}
break; case Jackpot:
switch (combo[1])
{
case Jackpot:
if (combo[2] == Jackpot)
{
winnings = 1000;
winner =true;
gameOn =false;
cout<<“You hit the Jackpot!!!”<<endl;
}
elseif (combo[2] == Cherry) winnings = 1;
break;
case Cherry:
winnings = 1;
if (combo[2] == Cherry) winnings = rand()%4+2;
break;
default:
if (combo[2] == Cherry) winnings = 1;
break;
}
break;
}
if (winnings > 0) cout<<“You win “<< winnings <<endl;
thePot += winnings;
cout<<“You now have $”<<thePot<<endl;
combo.clear();
cout<<endl;
cin.get(checkKey);
if (checkKey !=’n’) gameOn =false;
}
while (!cin.get()){};
if (winner) cout<<“You walk away a winner.”<<endl;
elseif (thePot< 0) cout<<“Good bye.”<<endl;
elsecout<<“You have lost all your money.”<<endl;
// Wait for user input to close program when debugging.
cin.get();
return 0;
}
//–end of main program————-
//———————————-
3. 3.Create a Program FromPseudocode
This exercise will be to use pseudocode (in the form of comments) to write a program to simulate a horse race. You will need the following
variables.
• structHorse—>member variables
o string name: the name of the horse
o intdistance: how far the horse has traveled
o intoffset: used to track penalties and bonuses from events
o intID: the number of the horse and index for horses
• global constant inthorseCount = 6: the number of horses in the race
• global constant inttrackLength = 100: the length of the race track
• std::array <Horse, horseCount> horses
• intdie1, die2 for die rolls (These are optional—the sum can be generated without them.)
• intsumis used to store the sum of the die rolls.
• intwinneris the winning horse’s ID.
• intleadis usedto track the distance of the leading horse.
• intbet is the amount bet on the race.
• intcash is the amount of money the player has.
• boolracing is a flag used in the Do-Whileracing loop.While it is true, the race continues.
• boolplaying is a flag used in the Do-Whilegame loop.While it is true, the game continues.
• inthNum is the number (ID) of the horse the player bet on.
Use a range-based For loop to initialize the horse’s data. Ask the player for names or hard code them—your choice.
At the start of each race, ask the player to make a bet and pick a horse.
Each turn during the race, each horse will move forward based on the sum of the roll of two six-sided dice (1–6). This value is augmented
by an offset. The offset can be negative or positive. Add the offset to the sum of the dice. (Note:If the offset is negative, adding to the sum
will reduce the sum’s value.) If the sum is negative, store the negative value in offset and leave the horse’s distance value unchanged. If the
sum is positive, add it to the horse’s distance and set the offset to zero. Once any horse has gone more than the length of the track, the
race is over and the horse with the greatest distance value wins. Add six times the bet to cash if the player wins, or subtract the bet from
cash if the player loses. The game is over when the player has run out of money. You also quit when the player bets $0 or less.
The offset value is calculated using a Switch statement and a random number between 0 and 15. If the number is 0 or 1, the horse breaks
stride and the offset is negative 1 or 2 (randomly selected). If the random number is 2 or 3, the horse finds his stride and the offset is a
positive 1 or 2 (randomly selected). If the random number is 4, the horse stumbles and the offset is a negative 4–6 (randomly selected). If
the random number is 5, the horse has a burst of energy and the offset is a positive 4–6 (randomly selected).If the random number is 6–15,
nothing happens.
Reset the values of the horses distance and offset using a range-based For loop before each new race.
Here is the pseudocode.
// Week 4 Assignment-3
// Description: Horserace
//———————————-
//**begin #include files************
#include<iostream>// provides access to cin and cout
#include<array>// provides access to std::array
#include<time.h>// provides access to time()
#include<string>// provides access to getline()
#include<iomanip>
//–end of #include files———–
//———————————-
usingnamespacestd;
//———————————-
//**begin global constants**********
// struct for horse (name, distance, eventOffset, ID)
// number of horses (6)
// length of track (100)
//–end of global constants———
//———————————-
//**begin main program**************
int main()
{
// seed random number generator
srand(time(NULL));
// create and initialize variables
// create horses
// have user name horses (range-based for loop)
// two 1-6 dice
// sum of dice roll
// number of winning horse
// distance of leading horse
// bet
// cash on hand
// flag for ending race
// flag for ending game
// horse number bet on
// start of game loop
// ask for bet amount
//if bet is less than or equal to $0–quit
// else get the number of the horse being bet on
// start of race loop
// for each horse–use range-based for
// roll one 16 sided die to check on event
// use switch statement to handle event
//(see instructions for event)
// roll dice and,using offset, adjust horse’s distance
// check for race over
// report horse position
// check if this is leading horse and change lead and winner values if it is
//continue race loop until race is over
//end race loop
// report winner and settle bet
// if player has cash, get new bet, new horse, and start race
// else quit
// Wait for user input to close program when debugging.
cin.get();
return 0;
}
//–end of main program————-
//———————————-
DeVry Courses helps in providing the best essay writing service. If you need 100% original papers for DeVry GSP 115 Week 3 Assignment
latest, then contact us through call or live chat.
Download File Now

More Related Content

Similar to DeVry GSP 115 Week 3 Assignment latest

Node.js basics
Node.js basicsNode.js basics
Node.js basicsBen Lin
 
College for Women Department of Information Science
College for Women  Department of Information Science  College for Women  Department of Information Science
College for Women Department of Information Science WilheminaRossi174
 
College for women department of information science
College for women  department of information science  College for women  department of information science
College for women department of information science AMMY30
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing ScenarioTara Hardin
 
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...Nagios
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
Oracle pl sql
Oracle pl sqlOracle pl sql
Oracle pl sqlDurga Rao
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
Austin c-c++-meetup-feb2018-spectre
Austin c-c++-meetup-feb2018-spectreAustin c-c++-meetup-feb2018-spectre
Austin c-c++-meetup-feb2018-spectreKim Phillips
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Andrey Karpov
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresGowtham Reddy
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects Andrey Karpov
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxjacksnathalie
 
Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016PVS-Studio
 

Similar to DeVry GSP 115 Week 3 Assignment latest (20)

Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
College for Women Department of Information Science
College for Women  Department of Information Science  College for Women  Department of Information Science
College for Women Department of Information Science
 
College for women department of information science
College for women  department of information science  College for women  department of information science
College for women department of information science
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
Sge
SgeSge
Sge
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
 
lecture56.ppt
lecture56.pptlecture56.ppt
lecture56.ppt
 
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
Oracle pl sql
Oracle pl sqlOracle pl sql
Oracle pl sql
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
Austin c-c++-meetup-feb2018-spectre
Austin c-c++-meetup-feb2018-spectreAustin c-c++-meetup-feb2018-spectre
Austin c-c++-meetup-feb2018-spectre
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphores
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016
 

More from Atifkhilji

Devry CIS 355A Full Course Latest
Devry CIS 355A Full Course LatestDevry CIS 355A Full Course Latest
Devry CIS 355A Full Course LatestAtifkhilji
 
Devry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestDevry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestAtifkhilji
 
Devry CIS 246 Full Course Latest
Devry CIS 246 Full Course LatestDevry CIS 246 Full Course Latest
Devry CIS 246 Full Course LatestAtifkhilji
 
Devry GSCM 520 All Week Quiz Latest
Devry GSCM 520 All Week Quiz LatestDevry GSCM 520 All Week Quiz Latest
Devry GSCM 520 All Week Quiz LatestAtifkhilji
 
Devry GSCM 326 Full Course Latest
Devry GSCM 326 Full Course LatestDevry GSCM 326 Full Course Latest
Devry GSCM 326 Full Course LatestAtifkhilji
 
NU625-7 Full Course Herzing University
NU625-7 Full Course Herzing UniversityNU625-7 Full Course Herzing University
NU625-7 Full Course Herzing UniversityAtifkhilji
 
BIO 101 INTRODUCTION TO BIOLOGY TUI
BIO 101 INTRODUCTION TO BIOLOGY TUIBIO 101 INTRODUCTION TO BIOLOGY TUI
BIO 101 INTRODUCTION TO BIOLOGY TUIAtifkhilji
 

More from Atifkhilji (7)

Devry CIS 355A Full Course Latest
Devry CIS 355A Full Course LatestDevry CIS 355A Full Course Latest
Devry CIS 355A Full Course Latest
 
Devry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestDevry CIS 247 Full Course Latest
Devry CIS 247 Full Course Latest
 
Devry CIS 246 Full Course Latest
Devry CIS 246 Full Course LatestDevry CIS 246 Full Course Latest
Devry CIS 246 Full Course Latest
 
Devry GSCM 520 All Week Quiz Latest
Devry GSCM 520 All Week Quiz LatestDevry GSCM 520 All Week Quiz Latest
Devry GSCM 520 All Week Quiz Latest
 
Devry GSCM 326 Full Course Latest
Devry GSCM 326 Full Course LatestDevry GSCM 326 Full Course Latest
Devry GSCM 326 Full Course Latest
 
NU625-7 Full Course Herzing University
NU625-7 Full Course Herzing UniversityNU625-7 Full Course Herzing University
NU625-7 Full Course Herzing University
 
BIO 101 INTRODUCTION TO BIOLOGY TUI
BIO 101 INTRODUCTION TO BIOLOGY TUIBIO 101 INTRODUCTION TO BIOLOGY TUI
BIO 101 INTRODUCTION TO BIOLOGY TUI
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

DeVry GSP 115 Week 3 Assignment latest

  • 1. DeVry GSP 115 Week 3 Assignment latest Just Click on Below Link to Download This Course: https://www.devrycoursehelp.com/product/devry-gsp-115-week-3-assignment-latest/ Or Email us help@devrycoursehelp.com DeVry GSP 115 Week 3 Assignment latest Week 3: 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. 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************
  • 2. #include<iostream>// provides access to cin and cout #include<time.h>// 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; i<arraysize: i++); {
  • 3. 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 “<<arrayNum<<” to get “<<mysteryNum<<“? “; cin>> number; if (mysteryNum == arrayNum – number) { cout<<“You got the number!”<<endl; else { cout<<“That’s not the right number.”<<endl; endLoop =true; } } cin.get(); // Wait for user input to close program when debugging.
  • 4. cin.get(); return 0; } //–end of main program————- //———————————- 2. 2.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. 1.When you hit the return key, the wheel spins (you won’t actually see any spinning, just the results of the spin). 2. 2.You automatically bet $1 on each spin. 3. 3.If you get three of the same symbols, you win according to the following table. 4. a.Lemons—you keep your bet. 5. b.Cherries—you win $5. 6. c.Oranges—you win $10. 7. d.Bells—you win $15. 8. e.Jackpot—you win $1,000 and the game is over. 9. 4.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************
  • 5. #include<iostream>// provides access to cin and cout #include<iomanip> #include<array> #include<vector> //–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<string, 10> symbols;
  • 6. array<symbol, 10>eSymbols; int position; string selected; }; //create an array of three slot machine wheels array<Wheel, 3>slotMachine = { { { {“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”
  • 7. } } }; boolgameOn =true; bool winner =false; intthePot = 100; int bet = 1; vector<int> 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<<setw(10) << left <<slotMachine[i].selected.c_str() ; combo.push_back(slotMachine[i].eSymbols[slotMachine[i].position]); } if ((combo[0] == combo[1]) && (combo[1] == combo[2])) { if (combo[0] ==Lemon) { cout<<“You keep your bet.”<<endl;
  • 8. } elseif(combo[0] =Jackpot) { cout<<“**** You hit $1000 Jackpot!!! ****”<<endl; thePot += 1000; winner =true; gameOn =false; } else { cout<<“WINNER! You win $”<<combo[0]*5 <<endl; thePot += combo[0]*5; } } else { thePot -= bet; if (thePot> 0 ) gameOn=false; } cout<<“You now have $”<<thePot<<endl; combo.clear(); cout<<endl;
  • 9. cin.get(); } if (winner) cout<<“You walk away a winner.”<<endl; elsecout<<“You have lost all your money.”<<endl; // Wait for user input to close program when debugging. cin.get(); return 0; } //–end of main program————- //———————————- 3. 3.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
  • 10. // Description: Snowball fight – version 1 //———————————- //**begin #include files************ #include<iostream>// 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()
  • 11. { // 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————- //———————————- DeVry GSP 115 Week 4 Assignment latest Week 4: More Loops and Branching
  • 12. 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_W4_Assignments.docx.Submit it to the Week 4 assignment Dropbox. 1. 1.Compile Time Bugs Find and fix the compile 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”>. This assignment is meant to test your attention to detail and strengthen your debugging skills. Here is the code. // Week 4 Assignment-1 // Description: Compile time errors //———————————- //**begin #include files************ #include<iostream>// provides access to cin and cout #include<fstream>// provides access to file commands #include<string>// provides access to string commands #include<vectors>// provides access to std::vector //–end of #include files———– //———————————- usingnamespacestd; //———————————- //**begin global constants********** //–end of global constants———
  • 13. //———————————- //**begin main program************** int main() { // create and initialize variables stringmyTextString; stringmyFilename; vector<string>myStrVector; ifstreaminFile; ofstreamoutFile; cout<<“enter a file name (without an extension): “<<endl; getline(cin, myFilename); myFilename +=”.txt”; // open an output file outfile.open(myFilename); // write to a file for(inti = 0; i< 3;i++) { cout>>”enter a line of text: “; getline(cin, myTextString); outFile<<myTextString<<endl; }
  • 14. // close the file outFile.close(); // open an input file inFile.open(myFilename); // read from the file while (getline(inFile,myTextString)) { myStrVector.push_back(myTextString); } inFile.close(); // use a range-based for loop with a switch statement for(auto s: myStrVector) { cout<< s <<endl; charswitchFlag = s[0]; switch (switchFlag) { case”a”: cout<<“Hey, a vowel. The ‘a’ vowel actually.”<<endl; break; case’e’: cout<<“See vowel. See vowel run. run vowel, run. The ‘e’ vowel.”<<endl;
  • 15. break; case’i’: cout<<“I know. It’s a vowel. The ‘i’ vowel.”<<endl; break; case’o’: cout<<“Oh! Don’t you know, it’s the ‘o’ vowel.”<<endl; break; case’u’: cout<<“Whew! We got a you. Actually, the ‘u’ vowel.”<<endl; break; case’s’: cout<<“Oh great! I love ‘s’s. More ‘s’s, please.”<<endl; break; default cout<<“Nothing interesting here. I would really like to see an ‘s’.”<<endl; break; } } // Wait for user input to close program when debugging. cin.get(); return 0; }
  • 16. //–end of main program————- //———————————- 2. 2.Run-Time Errors We revisit the slot machine from last week, this time using a range-based For loop and the Switch statement. The Switch gives us some flexibility in coding the payouts. The code has one compile time bug and two run-time bugs. One of the run-time errors is a typo and the other is a logic error.Fix the compile error and run the program to find the run-time errors. Neither run-time bug will show up right away. This is to give you experience with testing your program to make sure it works. Often, although a program seems to be OK, it isn’t. Hint: Look for occasional erroneous wins of $1 when the first symbol is Bar. Here is the code. // Week 4 Assignment- 2 // Description: Run-time errors in more loops and branching //———————————- //**begin #include files************ #include<iostream>// provides access to cin and cout #include<iomanip> #include<array> #include<vector> //–end of #include files———– //———————————- usingnamespacestd; //———————————- //**begin global constants********** // number of positions on a reel (11)
  • 17. constintreelPositions = 11; //–end of global constants——— //———————————- //**begin main program************** int main() { // seed random number generator srand(time(NULL)); // create enum for symbols enum symbol { Lemon, Cherry, Orange, Bell, Bar, Jackpot }; // create a struct for slot machine wheel struct Wheel { array<string, reelPositions> symbols; array<symbol, 1reelPositions1>eSymbols; int position; string selected; }; //create an array of three slot machine wheels
  • 18. array<Wheel, 3>slotMachine = { { { {“Bar”,”Orange”,”Lemon”,”Orange”,”Bell”,”Orange”,”Bar”,”Lemon”,”Bell”,”Jackpot”,”Bell”}, {Bar, Orange, Lemon, Orange, Bell, Orange, Lemon, Bell, Jackpot, Bell}, 0,”Cherry” }, { {“Lemon”,”Bell”,”Lemon”,”Orange”,”Bell”,”Jackpot”,”Bar”,”Lemon”,”Cherry”,”Jackpot”,”Bell”}, {Lemon, Bell, Lemon, Orange, Bell, Jackpot, Bar, Lemon, Cherry, Jackpot, Bell}, 1,”Bell” }, { {“Cherry”,”Orange”,”Bar”,”Lemon”,”Orange”,”Lemon”,”Orange”,”Lemon”,”Cherry”,”Jackpot”,”Bell”}, {Cherry, Orange, Bar, Lemon, Orange, Lemon, Orange, Lemon, Cherry, Jackpot, Bell}, 2,”Lemon” } } }; boolgameOn =true; intthePot = 100;
  • 19. int bet = 1; bool winner =false; int winnings = 0; charcheckKey =’n’; vector<int> combo; cout<<“Hit return to bet, space and return to quit.”<<endl; while (gameOn) { for (auto s: slotMachine) { s.position=(s.position + rand()%reelPositions)%reelPositions; s.selected = s.symbols[s.position]; cout<<setw(10) << left <<s.selected.c_str() ; combo.push_back(s.eSymbols[s.position]); } winnings = -bet; switch (combo[0]); { case Lemon: switch (combo[1]) { case Lemon:
  • 20. if (combo[2] == Lemon) winnings = 1; elseif (combo[2] == Cherry) winnings = 1; break; case Cherry: winnings = 1; if (combo[2] == Cherry) winnings = rand()%4+2; break; default: if (combo[2] == Cherry) winnings = 1; break; } break; case Cherry: winnings = 1; if ((combo[1] == Cherry) && (combo[2] == Cherry)) winnings = 10; elseif ((combo[1] == Cherry) || (combo[2] == Cherry)) winnings = rand()%4+2; break; case Orange: switch (combo[1]) { case Orange: if (combo[2] == Orange) winnings = 15;
  • 21. elseif (combo[2] == Cherry) winnings = 1; break; case Cherry: winnings = 1; if (combo[2] == Cherry) winnings = rand()%4+2; break; default: if (combo[2] == Cherry) winnings = 1; break; } break; case Bell: switch (combo[1]) { case Bell: if (combo[2] == Bell) winnings = 20; elseif (combo[2] == Cherry) winnings = 1; break; case Cherry: winnings = 1; if (combo[2] == Cherry) winnings = rand()%4+2; break;
  • 22. default: if (combo[2] = Cherry) winnings = 1; break; } break; case Bar: switch (combo[1]) { case Bar: if (combo[2] == Bar) winnings = 40; elseif (combo[2] == Cherry) winnings = 1; break; case Cherry: winnings = 1; if (combo[2] == Cherry) winnings = rand()%4+2; break; default: if (combo[2] == Cherry) winnings = 1; break; } break; case Jackpot: switch (combo[1])
  • 23. { case Jackpot: if (combo[2] == Jackpot) { winnings = 1000; winner =true; gameOn =false; cout<<“You hit the Jackpot!!!”<<endl; } elseif (combo[2] == Cherry) winnings = 1; break; case Cherry: winnings = 1; if (combo[2] == Cherry) winnings = rand()%4+2; break; default: if (combo[2] == Cherry) winnings = 1; break; } break; } if (winnings > 0) cout<<“You win “<< winnings <<endl;
  • 24. thePot += winnings; cout<<“You now have $”<<thePot<<endl; combo.clear(); cout<<endl; cin.get(checkKey); if (checkKey !=’n’) gameOn =false; } while (!cin.get()){}; if (winner) cout<<“You walk away a winner.”<<endl; elseif (thePot< 0) cout<<“Good bye.”<<endl; elsecout<<“You have lost all your money.”<<endl; // Wait for user input to close program when debugging. cin.get(); return 0; } //–end of main program————- //———————————- 3. 3.Create a Program FromPseudocode This exercise will be to use pseudocode (in the form of comments) to write a program to simulate a horse race. You will need the following variables. • structHorse—>member variables o string name: the name of the horse
  • 25. o intdistance: how far the horse has traveled o intoffset: used to track penalties and bonuses from events o intID: the number of the horse and index for horses • global constant inthorseCount = 6: the number of horses in the race • global constant inttrackLength = 100: the length of the race track • std::array <Horse, horseCount> horses • intdie1, die2 for die rolls (These are optional—the sum can be generated without them.) • intsumis used to store the sum of the die rolls. • intwinneris the winning horse’s ID. • intleadis usedto track the distance of the leading horse. • intbet is the amount bet on the race. • intcash is the amount of money the player has. • boolracing is a flag used in the Do-Whileracing loop.While it is true, the race continues. • boolplaying is a flag used in the Do-Whilegame loop.While it is true, the game continues. • inthNum is the number (ID) of the horse the player bet on. Use a range-based For loop to initialize the horse’s data. Ask the player for names or hard code them—your choice. At the start of each race, ask the player to make a bet and pick a horse. Each turn during the race, each horse will move forward based on the sum of the roll of two six-sided dice (1–6). This value is augmented by an offset. The offset can be negative or positive. Add the offset to the sum of the dice. (Note:If the offset is negative, adding to the sum will reduce the sum’s value.) If the sum is negative, store the negative value in offset and leave the horse’s distance value unchanged. If the sum is positive, add it to the horse’s distance and set the offset to zero. Once any horse has gone more than the length of the track, the race is over and the horse with the greatest distance value wins. Add six times the bet to cash if the player wins, or subtract the bet from cash if the player loses. The game is over when the player has run out of money. You also quit when the player bets $0 or less. The offset value is calculated using a Switch statement and a random number between 0 and 15. If the number is 0 or 1, the horse breaks stride and the offset is negative 1 or 2 (randomly selected). If the random number is 2 or 3, the horse finds his stride and the offset is a positive 1 or 2 (randomly selected). If the random number is 4, the horse stumbles and the offset is a negative 4–6 (randomly selected). If the random number is 5, the horse has a burst of energy and the offset is a positive 4–6 (randomly selected).If the random number is 6–15, nothing happens. Reset the values of the horses distance and offset using a range-based For loop before each new race.
  • 26. Here is the pseudocode. // Week 4 Assignment-3 // Description: Horserace //———————————- //**begin #include files************ #include<iostream>// provides access to cin and cout #include<array>// provides access to std::array #include<time.h>// provides access to time() #include<string>// provides access to getline() #include<iomanip> //–end of #include files———– //———————————- usingnamespacestd; //———————————- //**begin global constants********** // struct for horse (name, distance, eventOffset, ID) // number of horses (6) // length of track (100) //–end of global constants——— //———————————- //**begin main program************** int main()
  • 27. { // seed random number generator srand(time(NULL)); // create and initialize variables // create horses // have user name horses (range-based for loop) // two 1-6 dice // sum of dice roll // number of winning horse // distance of leading horse // bet // cash on hand // flag for ending race // flag for ending game // horse number bet on // start of game loop // ask for bet amount //if bet is less than or equal to $0–quit // else get the number of the horse being bet on // start of race loop // for each horse–use range-based for // roll one 16 sided die to check on event
  • 28. // use switch statement to handle event //(see instructions for event) // roll dice and,using offset, adjust horse’s distance // check for race over // report horse position // check if this is leading horse and change lead and winner values if it is //continue race loop until race is over //end race loop // report winner and settle bet // if player has cash, get new bet, new horse, and start race // else quit // Wait for user input to close program when debugging. cin.get(); return 0; } //–end of main program————- //———————————- DeVry Courses helps in providing the best essay writing service. If you need 100% original papers for DeVry GSP 115 Week 3 Assignment latest, then contact us through call or live chat.