Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++) File bowling.txt 2 8 1 X X 3 / 4 5 1 / X X 3 / 4 / 8 X X X X

(C++) File bowling.txt

2

8 1 X X 3 / 4 5 1 / X X 3 / 4 / 8

X X X X X X X X X X 9 /

The game of bowling consists of ten frames. For each frame, ten pins are set at the end of a lane. The players objective is to knock down all the pins by rolling a ball down the lane. The bowler is allowed up to two rolls to knock down all the pins. If the bowler knocks them all down on the first attempt, the frame is scored as a strike. If the bowler does not knock them down on the first attempt in the frame the bowler is allowed a second attempt to knock down the remaining pins. If the bowler succeeds in knocking the rest of the pins down in the second attempt, the frame is scored as a spare.

The score for a bowling game consists of a sum of the scores for each frame. The score for frames 1-9 will be the total number of pins knocked down in the frame, plus bonuses for strikes and spares. If a bowler scores a strike in a frame, the score for that frame is ten plus the sum of the next two rolls. If a bowler scores a spare in a frame, the score for that frame is ten plus the score of the next roll.

If a bowler scores a strike in the tenth (final) frame, the bowler is allowed two more rolls; a bowler scoring a spare in the tenth frame is allowed one more roll. The score for frame 10 is the total number of pins knocked down in that frame. The maximum possible score in a game of bowling (strikes in all ten frames plus two extra strikes for the tenth frame strike) is 300. Write a C++ program to score a bowling match.

Input will be from a datafile. The first line will be a single integer, n, indicating the number of games to be scored. Each of the next n lines will represent a single game and will consist of all the rolls for that game. The outcome of each roll will be indicated with an integer representing the number of pins knocked down, a '/ ' indicates a spare, or a 'X' for a strike. Output the frame/total game score using the format shown below. Enter the file name interactively from the keyboard. Use user-defined functions/methods in your program. Do not use break or continue statements. Refer to the sample output below.

image text in transcribed

Sample Run Enter the file name: bowling. txt Game 1: Frames 18 8-1 X 34-5 1/X 34/8 75 95 118138 152 17 Total Score: 170 Game 2: Frames 18 3e 180 210 24 269 289 Total Score: 289

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions