Question: Complete the following c + + code:aincluda Assignment You will be writing a program to score bowling for several players. Your job will be to
Complete the following c code:aincluda Assignment
You will be writing a program to score bowling for several players. Your job will be to ask for players and their scores, then add up their score. When all
players have been entered, the user will type "done". Then, your program will tally up the worst and best player and output who won and who lost the
game.
Restrictions
You must use a vector to store all of the player names. All player names will be a single name.
You must use another vector to store the total score for each player. You must calculate the total score for each player after all rolls have been
entered.
You must use an array or a vector to store each roll's value see rubric below for more hints
The number of rolls is variable depending on whether the player threw a strike knocked down pins in one roll spare, or neither. Please see
"Scoring Bowling" below.
You must use a For loop to input the roll values into the arrayvector whichever you choose for #
If the user types "done" before entering any names, output No players were entered."
In the event of a tie, the first player lowest vector index to obtain the best or worst score is printed.
You can assume that the user will input valid scores. You do not need to perform error checking for invalid input. Hints
Collect ALL the pins knocked down for each roll before attempting to calculate the player's total score. It's much more difficult to calculate the total
score as you play, luckily, you are just calculating the score after the game is complete.
I suggest using a whiletrue loop for the data collection. The word "done" can be the check to break you out of the loop. Inside the loop, you can
ask for the player's name, gather the rolls for the player, and calculate the total score for that player and store it in scores After you exit the
whiletrue loop, see and print who won.
The players and scores vectors should be parallel vectors. playersi should be a name and scoresi should be that person's score. Each time you
iterate through the whiletrue loop, you gathering data for a new person, so each of these vectors should get a pushback.
The arrayvector to store each roll's value # in restrictions is something you will reuse for each person. It has a size of : frames have rolls
max, th frame has rolls max. So is total rolls. Once you calculate the person's final score taken from data in this rolls array you no
longer need the roll data for that person, so we can reuse it If you don't use a roll ie you get a strike so you skip the nd roll for the frame then
the "skipped" roll should just have a for that index. For example, if rolls is equal to that means you got a strike on the first frame. Then
rolls must be since you won't have a second roll for frame
When calculating the total score, you need to account for spares, strikes, double strikes in frames only and your normal roll that's not any of
these. Note that John in the first game below scored a perfect score of with all strikes. Note that the second game has no players.
Enter player's name done for no more players: John
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter player's name done for no more players: Cheryl
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score for frame roll :
Enter score f
AEncludt
Wineluda
AEneludd
using namaspace ;
cort at andl;
rallinput;?
if xoli.
Frod: input the last xall if notded
raturn playerholls;
int ealeulataplayartsaracant vactarint" tplayaxhalla f
int playtrofeara ;
adga cata: if thare is a daubla strika on and traat a lika a
rod: ealculate the frime sears
xatuxn playmxycaxa;
Z This line proventa the progran froe seg foulting if na playari mext
playymanasanpty i
Ptahn tearad sue.,
ruod: print rusulty
int amin I
thile yru
titing inputstxing;
if inputstring danof
hore: don't do any of the sunnary hase, axit the loap first
const yectarsint playaxhalla inputplayaraalla;
const int playerscora calculataplayerscaraplayurnalls;
F: stary the numa and scars
throw funtimartarYnylitid input;
printGanesumearyplayerhanes playorscaran;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
