/*Write a program that display the total time in 24-hour clock format having fixed time 12:34:56 and 10:35:14. One constructor should initialize member data hour, minute and second to 0 and another should initialize it to fixed values. Other two member functions should add two objects of type time passed as arguments and display the result.*/
/*By Sailesh Dhoju*/
#include<iostream.h>
#include<conio.h>
class time
{
private:
int hr,min,sec;
public:
time ()
{
hr=0;
min=0;
sec=0;
}
time (int a,int b,int c)
{
hr=a;
min=b;
sec=c;
}
void sum(time t1,time t2)
{
hr=t1.hr+t2.hr;
min=t1.min+t2.min;
sec=t1.sec+t2.sec;
min=min+sec/60;
hr=hr+min/60;
hr=hr%24;
min=min%60;
sec=sec%60;
}
void display()
{
cout<<hr<<":"<<min<<":"<<sec<<endl;
}
~time(){cout<<endl<<"DESTROYED"<<endl;}
};
int main()
{
clrscr();
time t1(12,34,56),t2(10,35,14),t3;
t1.display();
t2.display();
t3.sum(t1,t2);
t3.display();
getch();
return(0);
}
No comments:
Post a Comment