You are on page 1of 3

Q3 solution:

#include<iostream>
#include<conio.h>
using namespace std;

class time
{
int hours, minutes, seconds;
public:
time(): hours(0), minutes(0), seconds(0) {}
time(int h, int m, int s): hours(h), minutes(m), seconds(s) {}
void display()
{
cout<<hours<<":"<<minutes<<":"<<seconds;
}
void check()
{
if(seconds>59) {seconds-=59; minutes++;}
if(minutes>59) {minutes-=59; hours++;}
}
time operator + (time);
};

time time::operator +(time t2)

{
int i= hours+ t2.hours;
int j= minutes+ t2.minutes;
int k= seconds+ t2.seconds;
return time(i,j,k);
}
void main(void)
{
time t0(12, 34, 4), t1(3, 34, 45);
time t3;
do
{
t3 = t1+t0;
t3.check();
t3.display();
cout<<"\n\n !Press c to continue or any key to
exit."<<endl<<endl;
}
While
(getch()=='c');
}

Output:

You might also like