Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Prove the combinatorial identity?

Answered: 1 week ago

Question

_____ unions represent members of the same industry

Answered: 1 week ago