#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class clock
{
private:
int hr;
int min;
public:
void gettime(int hh,int mm)
{
hr=hh;
min=mm;
}
void showtime()
{
cout<<hr<<"Hours and "<<min<<"Minutes"<<endl;
}
clock operator +(clock);
};
clock clock :: operator +(clock t)
{
clock temp;
temp.min=(min+t.min)%60;
temp.hr=(hr+t.hr)+(min+t.min)/60;
return temp;
}
void main()
{
clrscr();
clock t1,t2,t3;
t1.gettime(1,25);
t2.gettime(3,50);
t3=t1+t2;
cout<<endl<<"Time 1 :";
t1.showtime();
cout<<endl<<"Time 2 :";
t2.showtime();
cout<<endl<<"Total Duration:";
t3.showtime();
getch();
}
#include<conio.h>
#include<iomanip.h>
class clock
{
private:
int hr;
int min;
public:
void gettime(int hh,int mm)
{
hr=hh;
min=mm;
}
void showtime()
{
cout<<hr<<"Hours and "<<min<<"Minutes"<<endl;
}
clock operator +(clock);
};
clock clock :: operator +(clock t)
{
clock temp;
temp.min=(min+t.min)%60;
temp.hr=(hr+t.hr)+(min+t.min)/60;
return temp;
}
void main()
{
clrscr();
clock t1,t2,t3;
t1.gettime(1,25);
t2.gettime(3,50);
t3=t1+t2;
cout<<endl<<"Time 1 :";
t1.showtime();
cout<<endl<<"Time 2 :";
t2.showtime();
cout<<endl<<"Total Duration:";
t3.showtime();
getch();
}
No comments:
Post a Comment