You are on page 1of 2

#include<iostream>

using namespace std;

class time
{
private:
int hours;
int minutes;
int seconds;
public:
time() : hours(0), minutes(0), seconds(0)
{ }

time(int h, int m, int s) : hours(h), minutes(m), seconds(s)


{ }

void displayTime() const


{
if(hours<10)
cout<<"0";
cout<<hours<<":";
if(minutes<10)
cout<<"0";
cout<<minutes<<":";
if(seconds<10)
cout<<"0";
cout<<seconds<<endl;
}

time checkTime(time t)
{
if(t.seconds>= 60)
{
t.seconds= t.seconds - 60;
++t.minutes;
}

if(t.minutes>=60)
{
t.minutes= t.minutes - 60;
++t.hours;
}

if(t.hours>=24)
t.hours= t.hours -24;
return time(t.hours, t.minutes, t.seconds);
} // To check the time for addition

time sCheck(time t)
{
if(t.seconds<0)
{
t.seconds = t.seconds + 60;
}
if(t.minutes<0)
t.minutes = t.minutes + 60;
if(t.hours<0)
t.hours = t.hours + 24;
return checkTime(time(t.hours, t.minutes, t.seconds));
} // to check the time for sub

time subPre(time t) // for prefix Sub


{
if(seconds == 0)
�t.minutes;
�seconds;
if(minutes == 0)
�t.hours;
�minutes;
�hours;

return sCheck(time(hours, minutes, seconds));


}

void operator ++() //prefix


{ checkTime(time(++hours, ++minutes, ++seconds)); }

void operator �() //prefix


{ subPre(time(hours, minutes, seconds)); }

time subPost(time t) // for prefix Sub


{
if(seconds == 0)
t.minutes�;
seconds�;
if(minutes == 0)
t.hours�;
minutes�;
hours�;

return sCheck(time(hours, minutes, seconds));


}

void operator ++ (int) //postfix


{ checkTime(time(hours++, minutes++, seconds++)); }

void operator � (int) //postfix


{ subPost(time(hours, minutes, seconds)); }

};

int main()
{
time t1(25, 00, 59);

t1 = t1.checkTime(t1); // Will correct the time


t1.displayTime(); // 01:00:59

++t1;
t1 = t1.checkTime(t1); //It will correct the time
t1.displayTime(); // 01:02:00

�t1;
t1 = t1.checkTime(t1);
t1.displayTime();

return 0;
}

You might also like