C++ Program (Add Two Times)

#include<iostream.h>
#include<conio.h>

class time
{
public:
int hours,minutes,seconds;
void enter();
void addtime(time,time);
};
void time::enter()
{
cout<<“\t\t\tENTER TIME IN TT FORMAT:”;
cout<<“\nHours:”;
cin>>hours;
cout<<“\nMinutes:”;
cin>>minutes;
cout<<“\nseconds:”;
cin>>seconds;
}
void time::addtime(time t1,time t2)
{
int hr,min,sec;
sec=t1.seconds+t2.seconds;
min=t1.minutes+t2.minutes+sec/60;
sec%=60;
hr=t1.hours+t2.hours+min/60;
min%=60;
cout<<“\t\t\t\nRESULTANT TIME”;
cout<<“\nHours=”<<hr;
cout<<“\nMinutes=”<<min;
cout<<“\nSeconds=”<<sec;
}
void main()
{
clrscr();
time ob1,ob2,ob3;
ob1.enter();
ob2.enter();
ob3.addtime(ob1,ob2);
getch();
}

Comments

Popular Posts