Question #255647

Write a program to add two objects of time class. Overload the operator ‘==’ to compare two objects and display whether they are equal or not. Also rewrite this program to overload the operators as friend function.


Expert's answer

#include <iostream>
#include <string>


using namespace std;




class Time {
public:
	Time() : t(clock()) {}
	bool operator==(const Time &T){
		return this->t == T.t;
	}


	time_t t;
};




int main() {
	Time T1;
	Time T2;
	cout << (T1 == T2);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS