Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you modifey my code to using the following reqirements. Your program must define a class that contains the following member variables and functions: a
can you modifey my code to using the following reqirements.
Your program must define a class that contains the following member variables and functions:
a private string that contains the name of the file.
a private array of the same structure as defined in Week : Programming Assignment. The structure should also be defined privately inside the class.
a public constructor that initializes the name of the file data member. The name of the data file should be passed into the constructor as a parameter.
a public Boolean returning function to read and store data into the array of the structures data member. This function should take no parameters and return a status of either success or failure ie true or false
a public void function that is used to calculate the average bowling score. This function should take no parameters. It should fill the array of structures data member with the average score of each bowler.
a public void function to output the results, including file name, bowler name, scores and average, to the console and a file named scores.dat. This function should take no parameters.
Your program must also implement a main function that is used to create an instance of the class mentioned above and call its public functions to exercisetest the classes implementation.
#include
#include
#include
#include
using namespace std;
#define NUMSCORES
Structure to hold bowler's data
struct Bowler
string name;
int scoresNUMSCORES;
int average;
;
Function to read and store data into an array of structures
bool GetBowlingDatastring file, vector& bowlers
ifstream finfilecstr;
if fin
return false;
Bowler tempBowler;
while fin tempBowler.name tempBowler.scores tempBowler.scores tempBowler.scores tempBowler.scores
bowlers.pushbacktempBowler;
fin.close;
return true;
Function to calculate the average bowling score
void CalculateAveragesvector& bowlers
for auto& bowler : bowlers
int total ;
for int i ; i NUMSCORES; i
total bowler.scoresi;
bowler.average total NUMSCORES;
Function to output the results to console and file
void PrettyPrintResultsconst vector& bowlers
ofstream outfilescoresdat";
if outfile
cerr "Unable to open file scores.dat." endl;
return;
for const auto& bowler : bowlers
cout bowler.name bowler.scores bowler.scores bowler.scores bowler.scores bowler.average endl;
outfile bowler.name bowler.scores bowler.scores bowler.scores bowler.scores bowler.average endl;
outfile.close;
int main
vector bowlers;
Reading bowling data from file
if GetBowlingDataBowlingScorestxt bowlers
cout "Error with the file" endl;
return ;
Calculating average scores
CalculateAveragesbowlers;
Printing results to console and file
PrettyPrintResultsbowlers;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started