【Description】 Write a program to define a class Time, which contains three member variables: hour, minute and second Please realize the following functions with operator overloading: input and output...


【Description】


Write a program to define a class Time, which contains three member variables: hour, minute and second


Please realize the following functions with operator overloading:




  • input and output time with >> and




  • use += and -= increase and decrease the time ,e.g.Time& operator+=(const Time&);Time& operator-=(const Time&);





【Input】




  • There are two line, each line is the time of a clock




  • Input format:hour minute second。




【Output】




  • There are two lines.




  • The first line is the output of time1 += (time2) ;




  • The second line is the output of time1 -= time2 ;




  • Output format:hour:minute:second;





  • Please read the




【Input example】


21 10 35


10 15 25


【Output example】


07:26:00


21:10:34



THE SOLUTION YOU SENT ME IS NOT GIVING THE REQUIRED OUTPUTS. PLEASE LOOK AND READ THE INPUT AND THE OUTPUT SAMPLES ABOVE CAREFULLY.



BELOW IS THE SLOTION YOU GAVE ME.



#include

using namespace std;

class Time

{


inthour;

intminute;

intsecond;


public:

Time(){}


Time(int h,int m,int s)

{

hour=h;

minute=m;

second=s;

}



friendistream&operator >>(istream&in,Time&t)

{

in>>t.hour>>t.minute>>t.second;

return in;

}


friendostream&operator<(ostream&out,>

{

out<><><><><><>

return out;

}



Timeoperator+(constTime&t1)

{

TimeT;

T.second=t1.second+second;

T.minute=t1.minute+minute;

T.hour=t1.hour+hour;

if(T.second>59)

{

T.second=T.second-60;

T.minute=T.minute+1;

}

if(T.minute>59)

{

T.minute=T.minute-60;

T.hour=T.hour+1;

}

if(T.hour>23)

T.hour=T.hour%24;

returnT;

}



Timeoperator-(constTime&t2)

{

Timediff;

if(t2.second>second){

--minute;

second+=60;

}


second=second-t2.second;

if(t2.minute>minute) {

--hour;

minute+=60;

}


minute=minute-t2.minute;

diff.hour=hour-t2.hour;

if(diff.hour<>

diff.hour+=24;

returndiff;



}



};









int main(){



Timetime1,time2,sum, diff;


cin>>time1;


cin>>time2;

sum=time1+time2;

diff=time1-time2;


cout<><><><>

}

Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here