Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

#include<iostream.

h>
#include<conio.h>
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<<"\nThe time is-"<<hours<<":"<<minutes<<":"<<seconds;
}
time add(time t1,time t2)
{
time t3;
t3.hours+=t1.hours+t2.hours+(t1.minutes+t2.minutes)/60;
t3.minutes+=(t1.minutes+t2.minutes)%60+(t1.seconds+t2.seconds)/60;
t3.seconds+=(t1.seconds+t2.seconds)%60;
return t3;
}
};
void main()
{
clrscr();
int h,m,s;
time t;
cout<<"Enter the first time in hh mm ss format(24 hr):";
cin>>h>>m>>s;
time t1(h,m,s);
cout<<"\nEnter the second time in hh mm ss format(24 hr):";
cin>>h>>m>>s;
time t2(h,m,s);
t=t.add(t1,t2);
cout<<"\nTimes added";
t.display();
getch();
}
//Output
Enter the first time in hh mm ss format(24 hr):12 55 32
Enter the second time in hh mm ss format(24 hr):13 25 44
Times added
The time is-26:21:16

You might also like