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/~mdanfor/cs222-w09/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.
<
The less than comparison operator. It is a member
function. It takes one class object and returns a bool. It compares the given
score to its own score to see which one is smaller. Don't forget to compare
both score and o_score.