Question: Use C++ language and it will have three files SportsMain.cpp, Team.cpp and Team.h . A sports association is going to contain an aggregate of sports
Use C++ language and it will have three files SportsMain.cpp, Team.cpp and Team.h .
A sports association is going to contain an aggregate of sports teams. In our lab, there are two types of sports teams - a hockey team and a baseball team. A hockey team will keep track of a team's wins, losses, ties and will calculate points based on these. A baseball team will keep track of a team's wins and losses and will calculate a winning percentage based on these (percentage in the context of baseball is a number between 0.000 and 1.000).
The main sports association program will create one sports association and add teams to it based on user input.
More details are given below:
The Team Abstract Class
The Team abstract class contains three functions which will be completed in the derived classes:
GetName(). This function returns the name of the team.
display(). This function displays information about the team.
operator==(). This function determines if one team is equal to another team. That is, if they are both hockey teams and they have the same number of points. Or if they are both baseball teams and they have the same winning percentage.
Team.cpp contains a function to create a team based on user input:
CreateTeam. This function creates and returns a pointer to a team based on user input.
The Baseball Team
The baseball team completes the abstract class and adds a constructor. The baseball team has a name, the number of wins, the number of losses, and the winning percentage:
BaseballTeam(). This function will take as arguments the name of the team, the wins, and the losses. The winning percentage can be calculated here from the number of wins and losses. The winning percentage is actually a decimal, not a percent, and is calculated as follows: wins/(wins+losses).
GetName(). This function returns the name of the team.
display(). This function displays information about the team. It returns an error status according to the enumeration in the base class. If all data is valid, it will display the team's name, wins, losses and winning percentage.
operator==(). This function determines if one team is equal to another team. If both teams are baseball teams and they both have the same winning percentage, the function returns true. False otherwise.
The Hockey Team
The hockey team completes the abstract class and adds a constructor. The hockey team has a name, the number of wins, the number of ties, the number of losses, and the total points:
HockeyTeam(). This function will take as arguments the name of the team, the wins, the ties, and the losses. The points can be calculated here as follows: points=2*wins+ties.
GetName(). This function returns the name of the team.
display(). This function displays information about the team. It returns an error status according to the enumeration in the base class. If all data is valid, it will display the team's name, wins, ties, losses and points.
operator==(). This function determines if one team is equal to another team. If both teams are hockey teams and they both have the same number of points, the function returns true. False otherwise.
The Sports Association
The sports association has a name and contains an aggregate of teams. These teams could be hockey teams, baseball teams or both. We will limit the number of teams to 4. It has the following functions:
SportsAssociation(). This function will take as an argument the name of the sports association.
operator+=(). This function overrides the += operator to add a team to the sports association. If the team added is "equal" to one of the existing teams, this function will print out the names of the two teams. To determine equality, use the operator== overload in the hockey team and baseball team classes. This function will also print out an error message if the number of teams has exceeded the limit (which in this example is 4 teams).
display(). This function performs no validation of data. It displays the name of the sports association along with calling the display() function for each team in its aggregation.
Sample Run
The main function has been given to you in the file SportsMain.cpp and the Teams class in the files Team.h and Team.cpp.
A sample run is as follows:
Enter 1 for a baseball team, or enter 2 for a hockey team. 1 What's the team's name? Rexdale Jays Enter the number of wins: 32 Enter the number of losses: 16 Enter 1 for a baseball team, or enter 2 for a hockey team. 2 What's the team's name? Rexdale Warriors Enter the number of wins: 23 Enter the number of ties: 5 Enter the number of losses: 18 Enter 1 for a baseball team, or enter 2 for a hockey team. 2 What's the team's name? Rexdale Warriors 2 Enter the number of wins: 15 Enter the number of ties: 4 Enter the number of losses: 16 Enter 1 for a baseball team, or enter 2 for a hockey team. 1 What's the team's name? Rexdale Leafs Enter the number of wins: 32 Enter the number of losses: 16 Rexdale Jays is similar to Rexdale Leafs. The Rexdale Sports Association has the following teams: Rexdale Jays has 32 wins and 16 losses for a winning percentage of 0.666667. Rexdale Warriors has 23 wins, 18 ties, and 5 losses for 64 points. Rexdale Warriors 2 has 15 wins, 16 ties, and 4 losses for 46 points. Rexdale Leafs has 32 wins and 16 losses for a winning percentage of 0.666667.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
