CS 12: Programming Assignment 5
Directory to turnin: as5
Due date: Tuesday Nov 14, 2000
Synopsis:
In this assignment, you are going to write a class that maintains
information about a sports team. Be sure to do a good job on this
assignment, as you will be using it in the next assignment.
Details:
This program should consist of 3 source files:
team.h:
This file contains the definition for the sports Team class. The
class definition should include member variables for the following:
- Team Name The name of the sports team.
- Season The current season (i.e. year, such as 1999, 2000,
etc.) which statistics are being gathered for.
- Number of Games The number of games the team has played
in the current season.
- Number of Wins The number of wins during the current
season.
- Number of Losses The number of losses during the current
season.
The class should also contain member functions to do the following:
- Constructor The constructor takes two parameters, the
name of the sports team and the current season. It should
initialize the appropriate data members. Use the strdup
function to initialize the team name.
- Display Prints all of the data members nicely
formatted.
- WinPercentage Calculates and returns the percentage of games
won in the current season. The result should be a floating
point number. (For example, if the team won 6 out of 11 games,
the percentage returned would be 54.55)
- WonAGame Updates the number of games played and the
number of wins. This method takes no parameters.
- LostAGame Updates the number of games played and the
number of losses. This method takes no parameters.
team.cpp:
This file will contain the implementation of the Team class.
main.cpp:
This file should contain your main function. It should prompt the
user for the name of a team and a season (i.e. year), then create
a sports team object. Note that a team name might be more than one
word, so use cin.getline() when prompting for this.
The function should then present a menu of options to the user:
P) play game
D) display team info
S) show winning percentage
Q) quit
Select option:
Depending on which option the user chooses, the appropriate Team
member function should be called. Put the menu in a loop so that after
performing each operation, the menu is shown again, until the user chooses
to quit.
If play game is selected, the user should be asked whether the team
won or lost the game, then call either WonAGame or LostAGame.
If show winning percentage is selected, the display should be rounded
to 2 decimal places.