Question
Operator overloading of ==, != and +. The equality(==) and inequality(!=) comparison operators can be written as functions or as methods in the clock_time class(
Operator overloading of ==, != and +.
The equality(==) and inequality(!=) comparison operators can be written as functions or as methods in the clock_time class( The clock time class returns hours, minutes and seconds e.g h=12 ,m=50,s=30). However, for this lab you should write them as free functions. Note that while you can use the public getter methods of clock_time to do the comparisons, it would be easier and faster to simply compare the internal representation of the two clock_time objects. However, to do that, you will first need to declare at least one of these as afriendfunction (the other one can easily be written in terms of the first). To do this, anywhere in your class declaration (at the top, before any visibility modifiers is traditional), simply add the line friend prototype, whereprototypeis the operator's prototype.
For the equality operator, you might have the line:
friend bool operator==(clock_time a, clock_time b);
Note that both of these operators must return a bool value.
Next, write the + operator, again as a free function, taking two clock_time values and returning a clock_time value. Again, this will be significantly cleaner and easier if you declare the operator function as a friend in clock_time and use the internal representation.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started