// Author: Isaac Acosta // Assigment 3 // Sample code by Bruce Gooch /* Sabermetrics uses statistical analysis to analyze baseball records and make determinations about player performance., especially...

1 answer below »
Dummy


// Author: Isaac Acosta // Assigment 3 // Sample code by Bruce Gooch /* Sabermetrics uses statistical analysis to analyze baseball records and make determinations about player performance., especially statistics that measure in-game activity. https://en.wikipedia.org/wiki/Sabermetrics#: 1. Write a baseball player class to store a player's name and at least ten statistics for a baseball player. (For a list of commonly used values, see Wikipedia. https://en.wikipedia.org/wiki/Baseball_statistics. Add constructors and a destructor to your class. Add a print function to your class. 2. Write a second class called baseballTeam that contains an array of at least nine baseball players. Add constructors and a destructor to your class. Your baseballTeam class must include two input functions, one that prompts a user input data from the keyboard and another that reads data from a file. Your baseballTeam class must contain a function to print the teams data. Add a functions to search the array to find a specific player and update a player's data. 3. Write a driver program, a program with a main function, to test your baseball player and baseballTeam classes. Your main function should create a team, read team data from a file, and allow a user to edit individual team member's data. Your program should be menu-driven, giving the user various choices. Before the program terminates, provide the user the option to save data in a file. 1. Baseball Player Constructors: Check - These are functions that are called when the object is being created Destructors: Check - These are functions that are called when the object is deleted Print function: Check - This is a function to print the object 2. Baseball Team Arrays: - [0, 1, 2, 3, 4] Input function: - reads from a file - reads from the terminal <-- last="" week="" cin!="" search="" function="" for="" the="" array:="" 3.="" driver="" function="" driver="" program="" -="" this="" is="" where="" our="" program="" starts="" reading="" from="" file="" saving="" to="" a="" file="" user="" input="" for="" menu="" */="" #include=""> #include using namespace std; class BaseballPlayer { public: void printBaseballPlayer() const; BaseballPlayer(); // Default Constructor BaseballPlayer(string name, double BattingAverage, int SingleHits, int BaseOnBalls, int BaseRuns, int HomeRuns, int HitByPitch, int StrikeOut, double SluggingAverage, int RunScored, int TripleHits); //Constructor with Parameters ~BaseballPlayer(); //destructor string getName() { return name; } private: string name; double BattingAverage; int SingleHits; int BaseOnBalls; int BaseRuns; int HomeRuns; int HitByPitch; int StrikeOut; double SluggingAverage; int RunsScored; int TripleHits; }; class BaseballTeam { public: void printBaseballTeam() const; void consoleInput (string fileName); void inputName(); bool findPlayer(const BaseballPlayer player); void editPlayer(BaseballPlayer player); BaseballTeam(); //Default Constructor ~BaseballTeam(); // destructor private: BaseballPlayer* team = new BaseballPlayer[9]; }; void BaseballPlayer::printBaseballPlayer() const { cout < "="" name:="" "="">< name="">< endl;="" cout="">< "="" batting="" average:="" "="">< battingaverage="">< endl;="" cout="">< "="" single="" hits:="" "="">< singlehits="">< endl;="" cout="">< "="" base="" on="" balls:="" "="">< baseonballs="">< endl;="" cout="">< "="" base="" runs:="" "="">< baseruns="">< endl;="" cout="">< "="" home="" runs:="" "="">< homeruns="">< endl;="" cout="">< "="" hit="" by="" pitch:="" "="">< hitbypitch="">< endl;="" cout="">< "="" strike="" out:="" "="">< strikeout="">< endl;="" cout="">< "="" slugging="" average:="" "="">< sluggingaverage="">< endl;="" cout="">< "="" run="" scored:="" "="">< runsscored="">< endl;="" cout="">< "="" triple="" hits:="" "=""><>< endl;="" }="" baseballplayer::baseballplayer()="" default="" constructor="" {="" this-="">name = "Joe Rock"; this->BattingAverage = 0.0; this->SingleHits = 2; this->BaseOnBalls = 1; this->BaseRuns = 4; this->HomeRuns = 0; this->HitByPitch = 3; this->StrikeOut = 1; this->SluggingAverage = 0.0; this->RunsScored = 2; this->TripleHits = 3; } BaseballPlayer::BaseballPlayer(string name, double battingAverage, int singleHits, int baseOnBalls, int baseRuns, int homeRuns, int hitByPitch, int strikeOut, double sluggingAverage, int runScored, int tripleHits) //Constructor with Parameters { this->name = name; this->BattingAverage = battingAverage; this->SingleHits = singleHits; this->BaseOnBalls = baseOnBalls; this->BaseRuns = baseRuns; this->HomeRuns = homeRuns; this->HitByPitch = hitByPitch; this->StrikeOut = strikeOut; this->SluggingAverage = sluggingAverage; this->RunsScored = runScored; this->TripleHits = tripleHits; } BaseballPlayer::~BaseballPlayer() { } void BaseballTeam::printBaseballTeam() const { cout < "team="" data:="" "="">< endl;="" }="" void="" baseballteam::consoleinput(string="" filename)="" {="" fstream="" file;="" file.open(filename,="" ios::out);="" if="" (!file)="" {="" cout="">< "file="" didn't="" open"="">< endl;="" return;="" }="" string="" name;="" double="" battingaverage;="" int="" singlehits;="" int="" baseonballs;="" int="" baseruns;="" int="" homeruns;="" int="" hitbypitch;="" int="" strikeout;="" double="" sluggingaverage;="" int="" runsscored;="" int="" triplehits;="" int="" playersloaded="0;" int="" playerdataloaded="0;" string="" line;="" while="" (getline(file,="" line))="" {="" if="" (line.c_str()[0]="=" '*')="" {="" this-="">team[playersLoaded] = BaseballPlayer(name, BattingAverage, SingleHits, BaseOnBalls, BaseRuns, HomeRuns, HitByPitch, StrikeOut, SluggingAverage, RunsScored, TripleHits); playersLoaded++; if (playersLoaded >= 9) { cout < "uh="" oh,="" too="" many="" players="" in="" the="" file!"="">< endl;="" break;="" }="" [player0="" |="" player1="" |="" player2="" |="" ...]="" continue;="" }="" reading="" from="" the="" file="" line="" by="" line="" if="" (playerdataloaded="=" 0)="" {="" name="line;" }="" else="" if="" (playerdataloaded="=" 1)="" {="" battingaverage="atof(line.c_str());" "2.0"="" --=""> 2.0 } else if (playerDataLoaded == 2) { SingleHits = atoi(line.c_str()); } else if (playerDataLoaded == 3) { BaseOnBalls = atoi(line.c_str()); } else if (playerDataLoaded == 4) { BaseRuns = atoi(line.c_str()); } else if (playerDataLoaded == 5) { HomeRuns = atoi(line.c_str()); } else if (playerDataLoaded == 6) { HitByPitch = atoi(line.c_str()); } else if (playerDataLoaded == 7) { StrikeOut = atoi(line.c_str()); } else if (playerDataLoaded == 8) {
Answered Same DayDec 29, 2021

Answer To: // Author: Isaac Acosta // Assigment 3 // Sample code by Bruce Gooch /* Sabermetrics uses...

Sonu answered on Feb 20 2021
145 Votes
#include
#include
using namespace std;
class BaseballPlayer
{
public:
void printBaseballPlayer();
BaseballPlayer(); // Default Constructor
BaseballPlayer(string name, double BattingAverage, int SingleHits,
int BaseOnBalls, int BaseRuns, int HomeRuns, int HitByPitch,
int StrikeOut, double SluggingAverage, int RunScored, int TripleHits); //Constructor with Parameters
~BaseballPlayer()
; //destructor

string getName() { return name; }
double getBattingAverage(){ return BattingAverage; }
int getSingleHits(){ return SingleHits; }
int getBaseOnBalls(){ return BaseOnBalls; }
int getBaseRuns(){ return BaseRuns; }
int getHomeRuns(){ return HomeRuns; }
int getHitByPitch(){ return HitByPitch; }
int getStrikeOut(){ return StrikeOut; }
double getSluggingAverage(){ return SluggingAverage; }
int getRunsScored(){ return RunsScored; }
int getTripleHits(){ return TripleHits; }

private:
string name;
double BattingAverage;
int SingleHits;
int BaseOnBalls;
int BaseRuns;
int HomeRuns;
int HitByPitch;
int StrikeOut;
double SluggingAverage;
int RunsScored;
int TripleHits;

};
class BaseballTeam
{
public:
void printBaseballTeam();
void consoleInput (string fileName);
void inputData();
int findPlayer(string name);
void editPlayer();
void makeFile(string file);
BaseballTeam(); //Default Constructor
~BaseballTeam(); // destructor

private:
BaseballPlayer* team = new BaseballPlayer[9];
int playerNumber = 0;
};
void BaseballPlayer::printBaseballPlayer()
{
cout << " Name: " << name << endl;
cout << " Batting Average: " << BattingAverage << endl;
cout << " Single Hits: " << SingleHits << endl;
cout << " Base on Balls: " << BaseOnBalls << endl;
cout << " Base Runs: " << BaseRuns << endl;
cout << " Home Runs: " << HomeRuns << endl;
cout << " Hit by Pitch: " << HitByPitch << endl;
cout << " Strike out: " << StrikeOut << endl;
cout << " Slugging Average: " << SluggingAverage << endl;
cout << " Run Scored: " << RunsScored << endl;
cout << " Triple Hits: " << TripleHits<< endl;
}
BaseballPlayer::BaseballPlayer() //Default Constructor
{
this->name = "Default Player(all the data is by default constructor)";
this->BattingAverage = 0.0;
this->SingleHits = 2;
this->BaseOnBalls = 1;
this->BaseRuns = 4;
this->HomeRuns = 0;
this->HitByPitch = 3;
this->StrikeOut = 1;
this->SluggingAverage = 0.0;
this->RunsScored = 2;
this->TripleHits = 3;
}
BaseballPlayer::BaseballPlayer(string name, double battingAverage, int singleHits,
int baseOnBalls, int baseRuns, int homeRuns, int hitByPitch,
int strikeOut, double sluggingAverage, int runScored, int tripleHits) //Constructor with Parameters
{
this->name = name;
this->BattingAverage = battingAverage;
this->SingleHits = singleHits;
this->BaseOnBalls = baseOnBalls;
this->BaseRuns = baseRuns;
this->HomeRuns = homeRuns;
this->HitByPitch = hitByPitch;
this->StrikeOut = strikeOut;
this->SluggingAverage = sluggingAverage;
this->RunsScored = runScored;
this->TripleHits = tripleHits;
}
BaseballPlayer::~BaseballPlayer()
{

}
void BaseballTeam::printBaseballTeam()
{
cout << "Team Data: " << endl;
for( int i = 0 ; i < min(9, playerNumber) ; i++){
team[i].printBaseballPlayer();
cout<<"*****************************************"< }
}
void BaseballTeam::makeFile(string file){
ofstream outfile;
outfile.open(file);
for( int i = 0 ; i < min(9, playerNumber) ; i++){
outfile << team[i].getName() << endl;
outfile << team[i].getBattingAverage() << endl;
outfile << team[i].getSingleHits() << endl;
outfile << team[i].getBaseOnBalls() << endl;
outfile << team[i].getBaseRuns() << endl;
outfile << team[i].getHomeRuns() << endl;
outfile << team[i].getHitByPitch() << endl;
outfile << team[i].getStrikeOut() << endl;
outfile << team[i].getSluggingAverage() << endl;
outfile << team[i].getRunsScored() << endl;
outfile << team[i].getTripleHits() << endl;
outfile << "*" << endl;
}
outfile.close();
}
void BaseballTeam::consoleInput(string fileName)
{
    
fstream file;
file.open(fileName);

if (!file)
{
cout << "File didn't open" << endl;
return;
}

string name;
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers