The purpose of this lab is to define operators for a given class.
Look at the score.cpp file that contains the Score class. You can copy it over to your current directory using:
wget http://www.cs.csubak.edu/~melissa/cs221/score.cppThis class has a converstion constructor and basic member functions defined, but no default constructor or input/output operators are defined. Until the operators are defined, the code will not compile because main() is using the operators. You will need to define the following operators:
<<
The output operator - It is a friend function that
takes two parameters. The first parameter is the output stream and the
second parameter is the class object. Call the member function
format_score()
in the class object with the output
stream as the argument to the member function.
>>
The input operator - It is also a friend function that
takes two parameters. The first parameter is the input stream and the
second parameter is the class object. Create a temporary integer in the
function and read from the input stream into the integer. Do NOT print
any statements with cout as main() has already prompted the user. Check
if the temporary integer is less than 0. If it is negative, reset it to
0. Then copy the temporary integer over to the "score" member variable
and call normalize_score()
to convert it into a Score object.