Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

// 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 »

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 a
ay 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 a
ay 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 Playe
Constructors: Check
XXXXXXXXXXThese are functions that are called when the object is being created
Destructors: Check
XXXXXXXXXXThese are functions that are called when the object is deleted
Print function: Check
XXXXXXXXXXThis is a function to print the object

2. Baseball Team
A
ays:
- [0, 1, 2, 3, 4]
Input function:
XXXXXXXXXXreads from a file
XXXXXXXXXXreads from the terminal <-- last week cin!
Search function for the a
ay:

3. Driver function
Driver program
XXXXXXXXXXThis is where our program starts
Reading from file
Saving to a file
User input for menu
*
#include #include using namespace std;
class BaseballPlaye
{
public:
void printBaseballPlayer() const;
BaseballPlayer();
Default Constructo
BaseballPlayer(string name, double BattingAverage, int SingleHits,
XXXXXXXXXXint BaseOnBalls, int BaseRuns, int HomeRuns, int HitByPitch,
XXXXXXXXXXint StrikeOut, double SluggingAverage, int RunScored, int TripleHits);
Constructor with Parameters
~BaseballPlayer();
destructo

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 Constructo
~BaseballTeam();
destructo

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: "
TripleHits
endl;
}
BaseballPlayer::BaseballPlayer()
Default Constructo
{
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,
XXXXXXXXXXint baseOnBalls, int baseRuns, int homeRuns, int hitByPitch,
XXXXXXXXXXint 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] == '*')
{
XXXXXXXXXXthis->team[playersLoaded] = BaseballPlayer(name, BattingAverage, SingleHits,
XXXXXXXXXXBaseOnBalls, BaseRuns, HomeRuns,
XXXXXXXXXXHitByPitch, StrikeOut, SluggingAverage,
XXXXXXXXXXRunsScored, TripleHits);
XXXXXXXXXXplayersLoaded++;
XXXXXXXXXXif (playersLoaded >= 9)
{
XXXXXXXXXXcout
"Uh oh, too many players in the file!"
endl;

eak;
}

[Player0 | Player1 | Player2 | ...]
XXXXXXXXXXcontinue;
}


Reading from the file line by line
if (playerDataLoaded == 0)
{
XXXXXXXXXXname = line;
}
else if (playerDataLoaded == 1)
{
XXXXXXXXXXBattingAverage = atof(line.c_str());
"2.0" --> 2.0
}
else if (playerDataLoaded == 2)
{
XXXXXXXXXXSingleHits = atoi(line.c_str());
}
else if (playerDataLoaded == 3)
{
XXXXXXXXXXBaseOnBalls = atoi(line.c_str());
}
else if (playerDataLoaded == 4)
{
XXXXXXXXXXBaseRuns = atoi(line.c_str());
}
else if (playerDataLoaded == 5)
{
XXXXXXXXXXHomeRuns = atoi(line.c_str());
}
else if (playerDataLoaded == 6)
{
XXXXXXXXXXHitByPitch = atoi(line.c_str());
}
else if (playerDataLoaded == 7)
{
XXXXXXXXXXStrikeOut = atoi(line.c_str());
}
else if (playerDataLoaded == 8)
{
Answered Same Day Dec 29, 2021

Solution

Sonu answered on Feb 20 2021
145 Votes
#include #include using namespace std;
class BaseballPlaye
{
public:
void printBaseballPlayer();
BaseballPlayer();
Default Constructo
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();
destructo

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 Constructo
~BaseballTeam();
destructo

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 Constructo
{
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
"*****************************************"
endl;
}
}
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