#include <iostream>
using namespace std;
/*
*/
class Date
{
int year, month, day;
public:
Date(int y, int m, int d)
:year(y), month(m), day(d)
{
}
public:
int getYear() { return year; }
int getMonth() { return month; }
int getDay() { return day; }
public:
void Print()
{
cout << year << "/";
cout << month << "/";
cout << day;
}
};
class Time
{
int hour, min, sec;
public:
Time(int h, int m, int s)
:hour(h), min(m), sec(s)
{
}
public:
int getHour() { return hour; }
int getMin() { return min; }
int getSec() { return sec; }
public:
void Print()
{
cout << hour << ":";
cout << sec << ":";
cout << min;
}
};
class DateTime
{
Date d;
Time t;
public:
DateTime(int y, int m, int d, int h, int mi, int s)
:d(y, m, d), t(h, mi, s)
{
}
void Print()// 2016/7/20 9:40:25
{
cout << d.getYear() <<"/"
<< d.getMonth() << "/"
<< d.getDay() << " "
<< t.getHour() << ":"
<< t.getMin() << ":"
<< t.getSec() << endl;
d.Print();
cout << " ";
t.Print();
cout << endl;
}
};
int main()
{
DateTime dt(2016, 7, 20, 9, 40, 25);
dt.Print(); // 2016/7/20 9:40:25
return 0;
}
'01.Bit 단기 > C++' 카테고리의 다른 글
29_C++ 실습 (0) | 2018.05.03 |
---|---|
29_new delete연산자 (0) | 2018.05.03 |
26_has a 객체초기화 (0) | 2018.05.03 |
25_has a 객체생성순서 (0) | 2018.05.03 |
24_상수멤버함수 (0) | 2018.05.03 |
댓글