#include<iostream.h>
#include<conio.h>
class time
{
int hr,mn,sec;
public:
void gettime()
{
cout<<"\nenter time in format of hh:mm:ss ";
cin>>hr>>mn>>sec;
}
void showtime()
{
cout<<"\ncurrent time :"<<hr<<":"<<mn<<":"<<sec;
}
void operator +(int n)
{
sec=sec+n;
if (sec>=60)
{
sec=sec%60;
mn++;
}
if(mn>=60)
{
mn=mn%60;
hr++;
}
if (hr>=24)
{
hr=0;
}
}
void operator <(time &a)
{
if(hr<a.hr)
cout<<"first time is less than second" ;
else
cout<<"first time is greater than second" ;
}
void operator ==(time &a)
{
if(hr==a.hr&&mn==a.mn&&sec==a.sec)
cout<<"two times are equal" ;
else
cout<<"two times are not equal" ;
}
};
void main()
{
clrscr();
time t1,t2,t3;
t1.gettime();
int n=0;
cout<<"enter seconds to be incremented.." ;
cin>>n;
t1+(n);
t1.showtime();
cout<<"\n1)use of `<' operater";
t2.gettime();
t2.showtime();
t1<t2;
cout<<"\n2)use of `=='operator" ;
t1.gettime();
t1.showtime();
t2.gettime();
t2.showtime();
t1==t2;
getch();
}
#include<conio.h>
class time
{
int hr,mn,sec;
public:
void gettime()
{
cout<<"\nenter time in format of hh:mm:ss ";
cin>>hr>>mn>>sec;
}
void showtime()
{
cout<<"\ncurrent time :"<<hr<<":"<<mn<<":"<<sec;
}
void operator +(int n)
{
sec=sec+n;
if (sec>=60)
{
sec=sec%60;
mn++;
}
if(mn>=60)
{
mn=mn%60;
hr++;
}
if (hr>=24)
{
hr=0;
}
}
void operator <(time &a)
{
if(hr<a.hr)
cout<<"first time is less than second" ;
else
cout<<"first time is greater than second" ;
}
void operator ==(time &a)
{
if(hr==a.hr&&mn==a.mn&&sec==a.sec)
cout<<"two times are equal" ;
else
cout<<"two times are not equal" ;
}
};
void main()
{
clrscr();
time t1,t2,t3;
t1.gettime();
int n=0;
cout<<"enter seconds to be incremented.." ;
cin>>n;
t1+(n);
t1.showtime();
cout<<"\n1)use of `<' operater";
t2.gettime();
t2.showtime();
t1<t2;
cout<<"\n2)use of `=='operator" ;
t1.gettime();
t1.showtime();
t2.gettime();
t2.showtime();
t1==t2;
getch();
}