PlayThis is C++ Problem, needs to be compiled with GNU++ Compiler All of the fil
ID: 3859627 • Letter: P
Question
PlayThis is C++ Problem, needs to be compiled with GNU++ Compiler
All of the files needed for this (baseball.cpp, player.h Player.cpp, and baseball.txt can be found here please do both parts.
https://drive.google.com/file/d/0B-4gpQ8Y_EDgYktqcl9LUzYzZW8/view?usp=sharing
Write a program in a file named Baseball.cpp that uses a Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class is declared in a file named Player.h, is stored in a file named Player.cpp and supports a constructor that sets the four data attributes (Number, Hits, Walks and Outs) equal to zero. In addition, there are extractor and mutator member functions for each of the data attributes. There is also an overload of the assignment operator foir assignment of Player objects. Finally, there is an overload of the output operatorExplanation / Answer
Answer:
#include "Team.h"
#include <iostream>
using namespace std;
int main() {
Team homeTeam;
Team visitingTeam;
Team yankees( "Yankees", 236 );
Team redSox( "Red Sox", 250 );
Team cardinals( "Cardinals", 267 );
Team rangers( "Rangers", 245 );
Team giants( "Giants", 214 );
Team phillies( "Phillies", 287 );
int homeTeamSelection = 0;
int visitingTeamSelection = 0;
cout << "Choose a home team:" << endl;
cout << "1 - Yankees" << endl;
cout << "2 - RedSox" << endl;
cout << "3 - Cardinals" << endl;
cout << "4 - Rangers" << endl;
cout << "5 - Gaints" << endl;
cout << "6 - Phillies" << endl;
cin >> homeTeamSelection;
cout << endl;
cout << "Choose a visiting team:" << endl;
cout << "1 - Yankees" << endl;
cout << "2 - RedSox" << endl;
cout << "3 - Cardinals" << endl;
cout << "4 - Rangers" << endl;
cout << "5 - Gaints" << endl;
cout << "6 - Phillies" << endl;
cin >> visitingTeamSelection;
cout << endl;
// Get Home Team
if( homeTeamSelection == 1 ) {
homeTeam = yankees;
}
else if( homeTeamSelection == 2 ) {
homeTeam = redSox;
}
else if( homeTeamSelection == 3 ) {
homeTeam = cardinals;
}
else if( homeTeamSelection == 4 ) {
homeTeam = rangers;
}
else if( homeTeamSelection == 5 ) {
homeTeam = giants;
}
else if( homeTeamSelection == 6 ) {
homeTeam = phillies;
}
cout << "Home Team Selected: " << homeTeam.name << endl;
// Get Visiting Team
if( visitingTeamSelection == 1 ) {
visitingTeam = yankees;
}
else if( visitingTeamSelection == 2 ) {
visitingTeam = redSox;
}
else if( visitingTeamSelection == 3 ) {
visitingTeam = cardinals;
}
else if( visitingTeamSelection == 4 ) {
visitingTeam = rangers;
}
else if( visitingTeamSelection == 5 ) {
visitingTeam = giants;
}
else if( visitingTeamSelection == 6 ) {
visitingTeam = phillies;
}
cout << "Visiting Team Selected: " << visitingTeam.name << endl;
cout << endl;
if( homeTeam.battingAverage > visitingTeam.battingAverage ) {
cout << homeTeam.name << " win!" << " Batting Average: " << homeTeam.battingAverage << endl;
cout << visitingTeam.name << " batting average: " << visitingTeam.battingAverage << endl;
}
else {
cout << visitingTeam.name << " win!" << " Batting Average: " << visitingTeam.battingAverage << endl;
cout << homeTeam.name << " batting average: " << homeTeam.battingAverage << endl;
}
return 0;
}