#include <iostream>
#include <string>
using namespace std;
class Time
{
public :
Time();
Time(const int hour, const int min, const int sec);
void SetHour(const int hour);
void SetMin(const int min);
void SetSec(const int sec);
int GetHour();
int GetMin();
int GetSec();
int CalSec();
void ShowTime();
private :
int hour, min, sec;
int t_sec;
};
Time::Time()
{
hour = 0;
min = 0;
sec = 0;
}
Time::Time(const int hour, const int min, const int sec)
{
this->hour = hour;
this->min = min;
this->sec = sec;
}
void Time::SetHour(const int hour)
{
this->hour = hour;
}
void Time::SetMin(const int min)
{
this->min = min;
}
void Time::SetSec(const int sec)
{
this->sec = sec;
}
int Time::GetHour()
{
return hour;
}
int Time::GetMin()
{
return min;
}
int Time::GetSec()
{
return sec;
}
int Time::CalSec()
{
// 시, 분, 초
// 초 단위로 변환
int totalSec = 0;
totalSec += 3600 * hour;
totalSec += 60 * min;
totalSec += sec;
return totalSec;
}
void Time::ShowTime()
{
cout << hour << "시 " << min << "분 " << sec << "초 입니다." << endl;
}
int main()
{
Time t1;
Time t2(1,20,40);
t1.SetHour(2);
t1.SetMin(20);
t1.SetSec(30);
// Time t3 = t1 + t2;
// Time t4 = t1 - t2;
// bool b1 = t1 > t2;
cout << "t1 :" << t1.CalSec() << endl;
cout << "t2 :" << t2.CalSec() << endl;
t1.ShowTime();
t2.ShowTime();
return 0;
}
'실습과제 모음' 카테고리의 다른 글
JAVA SQL + JFrame (0) | 2012.07.28 |
---|---|
JAVA Mysql 연결 실습 (0) | 2012.07.28 |
CPP ImaginaryNumber (0) | 2012.07.27 |
CPP 표준체중 계산 프로그램 (0) | 2012.07.26 |
CPP 함수 실습과제 (0) | 2012.07.25 |