#include<iostream.h>
#include<conio.h>
class time
{
int hours;
int min;
int sec;
public:
void gettime(int h,int m,int s)
{
hours=h;
min=m;
sec=s;
}
void puttime()
{
cout<<hours<<" : "<<min<<" : "<<sec;
}
void sum(time,time);
void convert();
};
void time::convert()
{
int Tsec;
Tsec=sec+(min*60)+(hours*60*60);
cout<<"\n\nTotal number of seconds of t1 : "<<Tsec;
}
void time::sum(time t1,time t2)
{
sec=t1.sec+t2.sec;
min=sec/60;
sec=sec%60;

min=min+t1.min+t2.min;
hours=min/60;
min=min%60;

hours=hours+t1.hours+t2.hours;
}
int main()
{
time t1,t2,t3;
t1.gettime(2,45,30);
t2.gettime(3,30,60);
clrscr();
cout<<"\n\nt1 = ";
t1.puttime();
cout<<"\n\nt2 = ";
t2.puttime();
cout<<"\n\nAddition of two object is : ";
t3.sum(t1,t2);
cout<<"\n\nt3 = ";
t3.puttime();
cout<<"\n\nConversion of time into seconds ";
t1.convert();
getch();
return(0);
}

Post a Comment

Previous Post Next Post