CS 12: Programming Assignment 6
Directory to turnin: as6
Due date: Tuesday Nov 21, 2000
Reading:
Dietel & Dietel, Chapter 9: Inheritance
Synopsis:
In this assignment, you will be using classes and
inheritance. You must use the sports team class you
developed in Assignment 5.
Files:
Following is the list of files you will create in this assignment:
- team.h (copy from as5)
- team.cpp (copy from as5)
- football.h
- football.cpp
- baseball.h
- baseball.cpp
- main.cpp
Team Class:
The Team class you wrote in the last assignment needs to be slightly
modified. The private section needs to be changed to protected.
Football Class:
Write a football team class which publicly inherits the sports team
class. This class should also contain the following new data members:
- Touchdowns Keeps track of the total number of
touchdowns for the team in the current season.
- Interceptions Keeps track of the total number
of interceptions for the team in the current season.
The class should also contain the following member functions:
- Constructor The constructor takes two parameters, the
name of the football team and the current season. It should
initialize the data members. Note that the base class
constructor should be used to initialize the base class
member variables.
- Display Prints all of the data members nicely
formatted.
- Stats Calculates and prints the percentage of
games won in the current season (note that the base class method
WinPercentage should be called to get this), the average
number of touchdowns per game, and the average number of interceptions
per game.
- WonAGame Updates the number of games and the number of wins
(note that the base class method WonAGame should be called to
do this). It also takes the number of touchdowns and interceptions
for that game as parameters and updates the appropriate member
variables.
- LostAGame Updates the number of games and the number of losses
(note that the base class method LostAGame should be called to
do this). It also takes the number of touchdowns and interceptions
for that game as parameters and updates the appropriate member
variables.
Baseball Class:
Write a baseball team class which publicly inherits the sports team
class. This class should also contain the following new data members:
- Home Runs Keeps track of the total number of home runs
for the team in the current season.
- RBIs Keeps track of the total number of runs batted in
for the team in the current season.
- Errors Keeps track of the total number of errors
for the team in the current season.
The class should also contain the following member functions:
- Constructor The constructor takes two parameters, the
name of the baseball team and the current season. It should
initialize the data members. Note that the base class
constructor should be used to initialize the base class
member variables.
- Display Prints all of the data members nicely
formatted.
- Stats Calculates and prints the percentage of
games won in the current season (note that the base class method
WinPercentage should be called to get this), the average
number of home runs per game, the average number of RBIs per game,
and the average number of errors per game.
- WonAGame Updates the number of games and the number of wins
(note that the base class method WonAGame should be called to
do this). It also takes the number of home runs, RBIs, and errors
for that game as parameters and updates the appropriate member
variables.
- LostAGame Updates the number of games and the number of losses
(note that the base class method LostAGame should be called to
do this). It also takes the number of home runs, RBIs, and errors
for that game as parameters and updates the appropriate member
variables.
main.cpp:
This file should contain your main function. It should prompt the
user for the name of a football team, the name of a baseball team,
and a season (i.e. year), then create a football team and a baseball
team object.
The function should then present a menu of options to the user:
P) play a game
D) display team info
S) show stats
Q) quit
Select option:
Whenever the user enters an option, you will need to ask whether the football
or baseball team should be used. Which team is being used will also affect
the play a game option. If a football game is being played, you will
need to prompt the user for whether the game was won or lost, the number of
touchdowns, and the number of interceptions. If a baseball game is being
played, you will need to prompt the user for whether the game was won or
lost, the number of home runs, the number of RBIs, and the number of errors.
Put the menu in a loop so that after performing each operation, the menu is
shown again, until the user chooses to quit.