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/cs222-w10/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 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 assignment operator. It is a member function. It
takes one parameter: the class object that is the source of the data to copy.
The score and o_score will be copied from this source into the current object.
+
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. Look at the adj()
member function
to see how to adjust score when it goes over the threshold value.
Don't forget to take the sumation of o_score for both parameters, otherwise
the billions counter will be lost.