Answer To: // Author: Isaac Acosta // Assigment 3 // Sample code by Bruce Gooch /* Sabermetrics uses...
Sonu answered on Feb 20 2021
#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;
...