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/cs222-w11/score.cppThis class has constructors and basic member functions defined, but no 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 input operator. It is a friend function that takes
two parameters. The first parameter is the input stream. The second parameter
is the class object. Input into a temporary integer and then use an if-else
statement similar to the integer conversion constructor to set the counters.
<<
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
formatScore()
in the class object with the output
stream as the argument to the member function.
+
The addition operator. It is a friend function that takes
two parameters. It takes two class objects and returns a new class object that
reflects the sum of the scores. Create a temporary Score object within the
function. Sum both the million and billion counters into the temporary Score.
Call normalizeScore()
on the temporary Score before returning it.
Don't forget to take the sumation of billion_counter for both parameters.