Project 1: Hockey Ratings
Due: Sunday, February 25, 2007, 11:59pm + 59 seconds
Objective
The objective of this project is to practice working with the
mechanics of C++ classes.
Background
Hockey players are often rated by a simple plus-minus rating. If their team
scores a goal when the player is on the ice, their rating is increased by 1.
If the opposing team scores a goal, then their rating is decreased by 1.
Negative ratings indicate a poor player. The plus-minus rating is preferred
over points for goals and assists because it recognizes that the
contribution of defensemen is not in scoring goals.
For this project, you will implement a program that reads in the players'
statistics, stores them in the players' records and stores the records
themselves in a priority queue. The priority queue will allow the coach
to pick a player with the highest plus-minus rating.
Assignment
Project 0: Due Friday, February 16, 2007
As stated in the course project policy, Project 0 is a required
part of the course. You must complete the following tasks by midnight
Friday, February 16.
- Copy to your own directory the following file in the
GL file system:
/afs/umbc.edu/users/c/h/chang/pub/cs202/proj0/secrets
- Add a comment of your own choosing to the bottom of
the file using a text editor of your choice.
- Submit the modified file to Project 0:
submit cs202 proj0 secrets
This shows that the system has been configured to accept
submissions from your GL account.
Project 1: Due Sunday, February 25, 2007
You are given the header files of two C++ classes: Stat
and Player: stat.h, player.h.
You must work with these files as given and not change them in
anyway. The Stat class is mostly a data class --- there
is an overloaded < operator to allow for comparisons. The Stat
class has just two data members: game and pmRating.
The game member holds the game number of a particular game. The
pmRating member holds the plus-minus rating of a player in that
game.
The Player class is more complicated. Since Player
has dynamically allocated data members, several member functions
have been implemented already, including the default constructor,
the destructor and the assignment operator. (You will find out
more about these later this semester). The implementations of
these functions are in player.cpp.
Player contains a vector of Stat records --- one
for each game that the player has played in. The medianRating
member contains the median plus-minus rating of the player in the
games he/she played in.
Part 1 of your assignment is to implement the following 3 member
functions in Player:
- void AddStat(Stat& s) ;
This member function should add s to the record
vector and update medianRating.
- void Print() const ;
This member function should print out the name
and medianRating fields.
- void PrintAll() const ;
This member function should print out the name
and medianRating fields as well as the
plus-minus rating for each game played.
Another member function called debug() exists to allow you to
have access to private data members for debugging purposes. You should
not use debug() in your final submission.
Part 2 of your assignment is to write a main program that
reads in the data for each player. For this project, we will use
UNIX input redirection to supply the input to the program. So, your
program should read from the standard input. Each player's record
must then be inserted into a priority queue, where the priority is
determined by the player's median plus-minus rating.
The priority queue data structure will maintain its items so that
the item with the highest priority is at the "top". If the top
item is popped off (i.e., removed), the priority queue adjusts
itself so that the item with the next highest priority is on
top. You will be using the priority queue class from the
Standard Template Library (STL). Details are below.
The main program must then remove the top 5 players from the priority
queue and print out their statistics using PrintAll(). Finally, the
program removes the rest of the players from the priority queue (in
medianRating order) and prints out their names and median rating
using Print().
Part 3 of your project is to create an input file that thoroughly
tests your program. Although your program does not have to deal
with improperly formatted input, you must still check that your program
works with "weird" but properly formatted input. Both sample input files
given to you are relatively nice. It is your responsibility as the
programmer to construct these "weird" test cases. Your grade for
this part of the project depends the "weirdness" of the input file
you construct.
Implementation Notes
- You should follow the CMSC202 Coding
Standards.
- When there are an even number of items, we will define
the median to be the higher of the two "middle" numbers. For example,
the median of (1, 3, 8, 9, 11, 24) is 9 (and is not
8.5).
- You should not modify the file player.cpp that has the
code for the Player member functions that are already implemented
for you. Put your code for the Player member functions in
a file called myplayer.cpp.
- The input for your program is in a convenient format. A player's
data starts with a line consisting of the player's name followed
by white space and the number of games played. The player's name does
not have any white space. In the lines that follow a player's name,
each line has two numbers, a game number followed by the player's
plus-minus rating for that game.
Two sample input files have been provided to you: input1.txt, input2.txt.
Sample output for input1.txt is also provided: output1.txt.
- To use the UNIX input/output redirection (assuming your executable file is called a.out):
./a.out output1.txt
- The method cin.eof() returns true when the end of file has been reached.
- There is an alternate constructor that assigns a player's name.
- STL priority queues are discussed only briefly in your textbook (p. 845). The
C/C++ Reference Site
has a listing of the methods available in a
priority queue.
In short you need to
#include
and use the definition:
priority_queue Q ;
After that, the push(), pop(), size(),
top() and empty() methods will be available.
Note that the return type of pop() is void
- The project files linked in this web page are also available
on the GL file system, in the directory:
/afs/umbc.edu/users/c/h/chang/pub/cs202/proj1/
You can copy these files to your own directory using the UNIX command:
cp /afs/umbc.edu/users/c/h/chang/pub/cs202/proj1/* .
Hints:
Depending on your project design, the following hints might be useful, or
not.
- There is a discussion of explicit constructor calls on
page 279 of your textbook.
- Recall that you can declare local variables inside
statement blocks marked by { and }. When
execution exits the block, the variables go "out of scope".
Grading
-
Projects will be graded on five criteria: correctness, design, style,
documentation and efficiency. So, turning in a project that merely "works"
is not sufficient to receive full credit.
-
If you did not look over the Academic
Conduct Policy for this course, do so now! Note that both the
copier and the "copy-ee" are penalized. If you do not understand
something about the policy, ask for clarification. Ignorance is
not an acceptable excuse.
-
Remember that the late policy is
a 25% penalty for submissions up to 24 hours late. Projects more than
1 day late will receive zero.
Turning in your program
Use the UNIX submit command to turn in your project.
You should submit 4 files:
- myplayer.cpp must contain the implementation
of the remaining member functions in player.h
- proj1.cpp must contain the main function
that completes Part 2 of the project.
- myinput.txt must be a test input file that
you created to show that you have fully exercised
your program.
- myoutput.txt must be the output of your
program given myinput.txt.
Do not submit any of the files that were given to you:
stat.h, player.h and player.cpp.
Since you are not allowed to change these files, your program should
compile and run correctly with the original versions of these files.
When you are done, use the class name 'cs202' and the project name 'proj1'
to submit your project. The UNIX command to do this should look like:
submit cs202 proj1 myplayer.cpp proj1.cpp myinput.txt myoutput.txt
Longer documentation of the submit system can be found
here.