#include

using namespace std;

class Time

{

private:

int hr;

int min;

int sec;

public:

Time(); // constructor

Time(int,int,int); // constructor

void get();

void show();

Time operator + (Time);

Time operator - (Time);

};

int main()

{

Time t1;

Time t2;

cout<<"Enter first time:";

t1.get();

cout<<"Enter second time:";

t2.get();

Time t_sum = t1 + t2;

Time t_diff = t1 - t2;

cout<<"Sum ";

t_sum.show();

cout<<"Diff ";

t_diff.show();

system("pause");

}

Time::Time()

{

hr=0;

min=0;

sec=0;

}

Time::Time(int h,int m,int s)

{

hr=h;

min=m;

sec=s;

}

void Time::get()

{

cout<<"nEnter hrs:";

cin>>hr;

cout<<"Enter min:";

cin>>min;

cout<<"Enter sec:";

cin>>sec;

}

void Time::show()

{

cout<<"Time is "<

":"<":"<}

Time Time::operator + ( Time t)

{

int h,m,s;

int sum;

sum = (hr + t.hr)*3600 + (min + t.min)*60 + sec + t.sec;

s = sum % 60;

sum = sum / 60;

m = sum % 60;

h = sum / 60;

return Time(h,m,s);

}

Time Time::operator - ( Time t)

{

int h,m,s;

int sum1,sum2,sum;

sum1 = (hr)*3600 + (min )*60 + sec ;

sum2 = (t.hr)*3600 + (t.min)*60 + t.sec;

if (sum1>sum2)

sum = sum1-sum2;

else

sum = sum2-sum1;

s = sum %60;

sum = sum/60;

m = sum % 60;

h = sum/60;

return Time(h,m,s);

}

By Azm

using namespace std;

class Time

{

private:

int hr;

int min;

int sec;

public:

Time(); // constructor

Time(int,int,int); // constructor

void get();

void show();

Time operator + (Time);

Time operator - (Time);

};

int main()

{

Time t1;

Time t2;

cout<<"Enter first time:";

t1.get();

cout<<"Enter second time:";

t2.get();

Time t_sum = t1 + t2;

Time t_diff = t1 - t2;

cout<<"Sum ";

t_sum.show();

cout<<"Diff ";

t_diff.show();

system("pause");

}

Time::Time()

{

hr=0;

min=0;

sec=0;

}

Time::Time(int h,int m,int s)

{

hr=h;

min=m;

sec=s;

}

void Time::get()

{

cout<<"nEnter hrs:";

cin>>hr;

cout<<"Enter min:";

cin>>min;

cout<<"Enter sec:";

cin>>sec;

}

void Time::show()

{

cout<<"Time is "<

":"<

Time Time::operator + ( Time t)

{

int h,m,s;

int sum;

sum = (hr + t.hr)*3600 + (min + t.min)*60 + sec + t.sec;

s = sum % 60;

sum = sum / 60;

m = sum % 60;

h = sum / 60;

return Time(h,m,s);

}

Time Time::operator - ( Time t)

{

int h,m,s;

int sum1,sum2,sum;

sum1 = (hr)*3600 + (min )*60 + sec ;

sum2 = (t.hr)*3600 + (t.min)*60 + t.sec;

if (sum1>sum2)

sum = sum1-sum2;

else

sum = sum2-sum1;

s = sum %60;

sum = sum/60;

m = sum % 60;

h = sum/60;

return Time(h,m,s);

}

By Azm