홈페이지에 있는 class1002.cpp 파일은 Time이라는 클래스를 선언, 정의하고 사용하는 예를 보여주고 있다. 이번 숙제에서는 이 Time 클래스의 기능을 확장하고 보완하는 것이 목적이다. 현재 Time 클래스는 내부적으로 시, 분, 초 정보를 저장하고 있고, 외부적으로는 생성자와 getter/setter, 그리고 + 오퍼레이터를 구현하고 있다. class1002.cpp 파일을 기반으로 하여 Time클래스에 아래와 같은 기능을 추가 및 보완하여라.
#include <iostream> #include <string> class Time { // fill here }; Time::Time(int hour, int min, int sec) { //fill here } Time::Time(int sec) { //fill here } Time operator+( Time t1, Time t2 ) { // fill here } 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() { 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"); }
학생이 선언/정의한 Time 클래스와 위에 제공된코드를 더해서 실행 하면 test 1부터 test 5까지 모두 pass하여야 한다. 한 pass당 2점씩 10점만점.