#include <iostream>
#include <string>

using namespace std;

// class Time
// Goal: manage time with hour, min, seconds
// funtion: perform plus, minus, comparison....

class Time {

	// private member variable (Data)
	int h;	// 0~23
	int m;	// 0~59
	int s;	// 0~59

	// public member function
public:
	// Constructor
	Time() { h=m=s=0; }
	Time( int hour, int min, int sec );
	Time( int sec );

	// accessor (getter)
	int getHour() { return h; }
	int getMin() { return m; }
	int getSec() { return s; }

	// accessor (setter)
	void setHour( int hour ) { if( 0 <= hour && hour <= 23 ) h = hour; }
	void setMin( int min ) { if( 0 <= min && min <= 59 ) m = min; }
	void setSec( int sec ) { if( 0 <= sec && sec <= 59 ) s = sec; }

	friend Time operator+( Time t1, Time t2 );

};

Time::Time(int hour, int min, int sec)
{
	s = ( 0 <= sec && sec <= 59 ) ? sec : -1;
	m = ( 0 <= min && min <= 59 ) ? min : -1;
	h = ( 0 <= hour && hour <= 23 ) ? hour : -1;
}

Time::Time(int sec)
{
	h = (sec / 3600) % 24;
	m = (sec % 3600) / 60;
	s = sec % 60;
}

Time operator+( Time t1, Time t2 ) {
	Time t( ( t1.h + t2.h )*3600 + (t1.m + t2.m) * 60 + (t1.s + t2.s) );
	return t;
}

void checkTime( string testname, Time t, int h, int m, int s )
{
    if( t.getHour() == h && t.getMin() == m && t.getSec() == s )
        cout << testname << " passed" << endl;
    else
        cout << testname << "  failed" << endl;
    
}
    

int main() 
{
	cout << "Welcome to HW4" << endl;

    Time t1(1, 2, 74);
    checkTime( "test 1", t1, 1, 2, -1 );
        
    Time t2(1, -3, 23);
    checkTime( "test 2", t2, 1, -1, 23 );
     
    Time t3(3700);
    checkTime( "test 3", t3, 1, 1, 40 );
            
    Time t4(3, 30, 30);
    Time t5(5, 40, 40);
    Time t6 = t4 + t5;
    
    checkTime( "test 4", t6, 9, 11, 10 );
    
    Time t7(15, 30, 30);
    Time t8(15, 20, 40);
    Time t9 = t7 + t8;

    checkTime( "test 5", t9, 6, 51, 10 );
    
    system("pause");
}