SOLUTION:
#include "stdafx.h"
#include "iostream"
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////
class time
{
private: int hrs, mints, secs;
public:
time(
) :hrs(0), mints(0), secs(0) {
/*Empty Body*/ }
time(int
h, int m, int s):hrs(h), mints(m), secs(s)
{ /*Empty Body*/ }
void
display( ) const
{ cout
<< hrs << ":" << mints << ":"
<< secs << endl; }
time
operator + (time) const;
};
//---------------------------------------------------------------------------------------
time time::operator + (time t2) const
{
int sec,
min, hr;
hr = hrs
+ t2.hrs;
min =
mints + t2.mints;
if(min
> 59)
{ min -=60; hr++; }
sec=secs
+ t2.secs;
if(sec
> 59)
{ sec -=60; min++; }
return
time(hr, min, sec);
}
/////////////////////////////////////////////////////////////////////////////////////////
void main( )
{
const
time time1(10,25,2),time2(5,59,59); time
time3;
cout
<< "Time1 is: "; time1.display(
);
cout
<< "Time2 is: "; time2.display(
);
time3 =
time1 + time2;
cout
<< "Time3 is: "; time3.display(
);
system("pause");
}
OUTPUT:
0 comments: