Create a C++ program using visual studio: The program is a bowling game: The obj
ID: 3841110 • Letter: C
Question
Create a C++ program using visual studio:
The program is a bowling game:
The objective: knock down as many pins with a ball.
1) Each game consists of 10 frames.
2) Frame is defined as:
a) Player gets 2 attempts per frame to knock down 10 pins.
b) Player rolls ball.
c) if player knocks down all 10 pins on 1st attempt, score for this frame is 10 plus the value of the next two rolls.
Therefore, score the frame cannot be computed until the next two rolls have been conducted. Utilize a frame score of 301 to check the result until the next two rolls have been conducted. There is no need for 2nd attempt. Game continues to next frame.
d1) if the player knocks down the remaining pins on the 2nd attempt, score for this frame is 10 plus the value of the next roll. Therefore, score the frame cannot be computed until the next roll has been conducted. Utilize a frame score of 301 to check the results until the next roll has been conducted.
d2) if the player does not knock down the remaining pins on the 2nd attempt, the score for this frame= 1st attempt + 2nd attempt.
After the 2nd attempt, game continues to next frame.
e) The score is cummulative i.e current score = pervious score + score for this frame. the testbench checks "the current score" for each frame.
3- game completes after 10 frames. final score is available as score of 10th frame in the testbench.
a) on the 10th frame, if player knocks down all the pins the 1st attempt, 2 additional rolls are provided. otherwise, if the player knocks down the remaining pins on the 2nd attempt, 1 additional is provided.
Explanation / Answer
bool *sparesframe = new1 bool;
bool *strikesframe = new1 bool;
int *score = new int(0);
using namespace std;
char *getdata()
{
char *tempdata = new char [40];
cout << "Enter name - *40 Characters maximum* : ";
cin.getline(tempdata, 40);
return tempdata;
}
char *getagainplay()
{
char *tempagainplay = new char[1];
cout <<endl << "Would you like to play again?/nEnter 1 for No,2 for Yes : " << endl;
cin >> *tempagainplay;
return tempagainplay;
}
int main ()
{
top:
int *counter =new int;
int *thrw1 = new int;
int *thrw2 = new int;
bool *strikes = new bool;
bool *spares = new bool;
char *againplay = new char;
char *bowlername = new char;
*againplay = 'n';
*spares = false;
*strikes = false;
*strikesframe = false;
*sparesframe = false;
*counter = 0;
*score = 0;
bowlerdata = getdata();
cout << "Please enter Throw 1 followed by the return key" << endl;
for(*counter = 0; *counter < 9; *counter++)
{
cout << "Enter Throw 1 " << endl;
cin >> *throw1;
if(*throw1 == 10)
{
*strikes = true;
*throw2 = 0;
}
else if(*throw1 < 10)
{
cout << "Enter Throw 2" << endl;
cin >> *throw2;
}
else
{ if(*throw1 > 10)
{
cout << "Be honest re enter throw number 1" << endl;
cin >> *throw1;
}
cout << "Enter Throw 2" << endl;
cin >> *throw2;
}
if(*throw1 + *throw2 == 10)
{
if(*throw1 != 10)
{
*spare = true;
*score = *score + *throw1 + *throw2;
}
else
*spare = false;
}
else if(*throw1 + *throw2 > 10)
{
do{
cout << "Be honest re enter throw number 2" << endl;
cin >> *throw2;
} while(*throw1 + *throw2 >10);
if(*throw1 + *throw2 == 10)
{
*spare = true;
*score = *score + *throw1 + *throw2;
}
else
*score = *score + *throw1 + *throw2;
}
else
*score = *score + *throw1 + *throw2;
if(*spareframe == true)
{
*score = *score + *throw1;
*spareframe = false;
}
else if(*strikeframe == true)
{
*score = *score + *throw1 + *throw2;
*strikeframe = false;
}
else
*score = *score;
if(*spare == true)
*spareframe = true;
else if(*strike == true)
*strikeframe = true;
else
*spare = false;
}
cout << "You Finished!" << endl;
cout << "Your Score is: " << *score << endl;
replay = getreplay();
if(*replay == 'y')
goto top;
else
cout << "Thanks for playing!" << endl;
delete counter, throw1, throw2, score;
delete strike, spare;
delete replay, bowlername;
delete spareframe, strikeframe;
return 0;
}