Question: can you modify this code to add. Your program must use one structure that contains the following member variables: a string data type that will
can you modify this code to add.
Your program must use one structure that contains the following member variables:
a string data type that will hold the name of the bowler.
a onedimensional array of integers to store the bowler's scores.
an integer to hold the average bowling score.
Your program must create and use an array of the structures mentioned previously.
Your program must contain at least the following functions:
a Boolean returning function to read and store data into an array of structures. The function should take as input parameters the file name and an empty array of structures, which it should fill from the file BowlingScorestxt and return a status of either success or failure ie true or false
a void function that is used to calculate the average bowling score. The function should take as input the array of structures which it should fill with the average score of each bowler.
a void function to output the results, ie bowler name, scores and average to the console and to a file named: scores.dat
Your program output must look identical to the image below or your score will be reduced.
#include
#include
#include
using namespace std;
#define SIZE
#define COL
this opens the file with data
bool GetBowlingDatastring file, string names int dataCOL
ifstream finfilecstr;
if fin
return false;
int count ;this goes in and finds the data and puts it into a varabile
while fin namescount datacount datacount datacount datacount
count;
return true;
double GetAverageScoreint dataCOL
int count ;
for int i ; i SIZE; i
if datai
count;
else
break;
double avg new doublecount;this finds the average score
for int i ; i count; i
avgidatai datai datai datai;
return avg;
void PrettyPrintResultsstring names int data double avg
int count ;
for int i ; i SIZE; i
if datai
count;
else
break;
this prints it
for int i ; i count; i
cout namesi datai datai datai datai avgi endl;
ofstream outfilescoresdat"; makes a file of score data.
if outfileisopen
outfile namesi datai datai datai datai avgi endl;
outfile.close;
else
cerr "Unable to open file." endl;this is if the file fails to open
int main
this makes the arrays you need
string namesSIZE;
int dataSIZECOL;
double avg;
this puts it into an array
for int i ; i SIZE; i
for int j ; j COL; j
dataij;
for int i ; i SIZE; i
namesi "Unknown";
this gets the avg scores from arrays you put in and opens file
bool status GetBowlingDataBowlingScorestxt names, data;
if status
cout "Error with the file
;
return ;
avg GetAverageScoredata;
PrettyPrintResultsnames data, avg;
return ;
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
