Answer to Question #255647 in C++ for William

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.


1
Expert's answer
2021-10-23T23:31:00-0400
#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!

Comments

William
26.10.21, 17:30

Thank you so much

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS