Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be writing an electronic bowling scoring program using functions, array

ID: 3625370 • Letter: Y

Question

You will be writing an electronic bowling scoring program using functions, arrays, and structures. Refer to the following website for the rules of scoring: http://en.wikipedia.org/wiki/Ten-pin_bowling

The program should allow multiple players (at most 10) to play the bowling game and keep track of each player’s score. In addition, the program should allow players to play the bowling game as many times as they want. The game consists of 10 frames. During each frame, a random number generator will generate numbers which will be used to calculate the score for that frame. At the end of each frame, your program should display the individual score for each frame that has been completed so far and the running total score. If a frame’s score is not available at the end of that frame, use “strike” or “spare” to indicate its status.


The following is an example program that generates a random number from 1 to 10.

#include
#include
using namespace std;
int main()
{
//declare variable to hold random number
int random;

//randomize number based on time
srand(time(NULL));

//generate random number from 1 to 10
random = rand() % 10 + 1;

cout<
return 0;
}


Explanation / Answer

please rate - thanks


#include <iostream>
#include <string>
#include <time.h>
#include <iomanip>
using namespace std;

struct game {
string Name;
int frame[11][2];
int score[10];
char prev;
char prev2;
};
void reset(game[],int);
void printScore (game[],int,int);
void score(game[],int,int,int,int);
void score10(game [],int,int,int);
int main ()
{game b[10];
int bowlers,i,f,ball1,ball2;
srand(time(0));
cout<<"How many bowlers are there? ";
cin>>bowlers;
do
{

reset(b,bowlers);
for(f=0;f<10;f++)
    {for(i=0;i<bowlers;i++)
        {ball1=rand()%11;
        ball2=0;
         if(ball1!=10)
               ball2=rand()%(11-ball1);
         score(b,i,f,ball1,ball2);
         if(f==9&&(ball1+ball2==10||b[i].prev2=='k'))
             score10(b,i,ball1,ball2);
         cout<<"Bowler "<<i+1<<" score after frame "<<f+1<<endl;
         printScore(b,i,f+1);
         }
     }
   
cout<<" New Game How many bowlers are there(0 to exit)? ";
cin>>bowlers;
}while(bowlers>0);

return 0;
}
void printScore(game b[],int i,int f)
{int j;
cout<<" ";
for(j=0;j<f;j++)
    cout<<"------";
cout<<endl;
for(j=0;j<f;j++)
       {cout<<"| ";
        if(b[i].frame[j][0]==10)
             cout<<"X|";
        else
             cout<<b[i].frame[j][0]<<"|";
        if(b[i].frame[j][1]==10||(b[i].frame[j][0]!=10&&b[i].frame[j][0]+b[i].frame[j][1]==10))
             cout<<"/";
        else
            cout<<b[i].frame[j][1];
        }
cout<<endl;
for(j=0;j<f;j++)
    cout<<"|     ";
cout<<"|"<<endl;
for(j=0;j<f;j++)
    cout<<"|     ";
cout<<"|"<<endl;
for(j=0;j<f;j++)
    cout<<"|"<<setw(5)<<b[i].score[j]<<"";
cout<<endl;      
for(i=0;i<f;i++)
    cout<<"------";
cout<<endl;
}
void score10(game b[],int i,int b1,int b2)
{b2=0;
b1=rand()%11;
if(b[i].prev=='p'||b[i].prev2=='k')
      b[i].score[9]+=b1;
else
    {
     if(b1!=10)
          b2=rand()%(11-b1);
     else
          b2==rand()%11;
      b[i].score[9]=b[i].score[9]+b1+b2;
     }
//cout<<b1<<" "<<b2<<" "<<b[i].score[9]<<endl;
}
void score(game b[],int i,int f,int b1,int b2)
{b[i].frame[f][0]=b1;
b[i].frame[f][1]=b2;
if(f==0)
      b[i].score[0]=b1+b2;
else if(f==1)
    {if(b[i].prev=='k')
         b[i].score[f-1]=10+b1+b2;
     else if(b[i].prev=='p')
         b[i].score[f-1]=10+b1;
     }
else if(f==2)
     {if(b[i].prev2=='k')
           b[i].score[f-2]=20+b1;
      if(b[i].prev=='k')
           b[i].score[f-1]=b[i].score[f-2]+10+b1+b2;
      else if(b[i].prev=='p')
           b[i].score[f-1]=b[i].score[f-2]+10+b1;
      }
else
      {if(b[i].prev2=='k')
           b[i].score[f-2]=b[i].score[f-3]+20+b1;
      if(b[i].prev=='k')
           b[i].score[f-1]=b[i].score[f-2]+10+b1+b2;
      else if(b[i].prev=='p')
           b[i].score[f-1]=b[i].score[f-2]+10+b1;
      }
if(f!=0)
    b[i].score[f]=b[i].score[f-1]+b1+b2;
b[i].prev2=b[i].prev;
if(b1==10)
   b[i].prev='k';
else if(b1+b2==10)
   b[i].prev='p';
else
    b[i].prev=' ';

//cout<<"frame="<<f<<" ball1="<<b1<<" ball2="<<b2<<" "<<b[i].prev<<" "<<b[i].prev2<<" ";
//for(int j=0;j<=f;j++)
//    cout<<b[i].score[j]<<" ";
//cout<<endl;

}   


   
void reset(game b[],int n)
{int i;
for(i=0;i<n;i++)
     {for(int j=0;j<10;j++)
          b[i].score[j]=0;
     b[i].prev=' ';
     b[i].prev2=' ';
     }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote