Write a C++ programwhich contains a class named Time having three datamembers .
ID: 3608009 • Letter: W
Question
Write a C++ programwhich contains a class named Time having three datamembers.
The class musthave
· Adefault andparameterizedconstructor
· show() methodto display the time in proper format like HH:MM:SS on thescreen
· get() methodto get time from user
· Overloaded Plus (+) and Minus (-)operators
· Adestructor
You will overload + and -operator for this class.
In main program make 3objects of the Time class time1, time2 and time3 and call theget()functions for time1 and time2 then perform time3 = tim1+time2 andthen you will display time3 using its show() function.
Note1: While Adding the timekeep in mind do not just add the hours into hours and minutes intominutes and seconds in seconds , e.g
10:25:10
+01:45:25
---------------------
11: 70: 35
Will not be correct, insteadyour code should add times like, Note that as number of minuteshave increased 60, hour have been increased.
10:25:10
+ 01:45:25
-------------------
12: 10: 35
Explanation / Answer
please rate - thanks /* Sample run with your data Enter the time Hour: 10 Minutes: 23 Seconds: 10 Enter the time Hour: 1 Minutes: 45 Seconds: 25 Time 1 : 10:23:10 Time 2 : 01:45:25 Added : 10:23:10 +01:45:25 ---------- 12:08:35 Subtracted: 10:23:10 -01:45:25 ---------- 08:37:45 Press any key to continue . . . */ #include #include using namespace std; void convert(int,int&,int&,int&); class Time { public: int hour,minute,second; Time() {hour=0; minute=0; second=0; } ~Time() {hour=0; minute=0; second=0; } Time(int h,int m,int s) {hour=h; minute=m; second=s; } void get() {coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.