1 #include <iostream>
2 using namespace std;
3
4 class Time
5 {
6 private:
7 int hour;
8 int minute;
9 int second;
10 public:
11 //Time() //无参够创函数
12 //{
13 // hour = 0; minute = 0; second = 0;
14 //}
15 //Time(int h, int m, int s) //带参构造函数
16 //{
17 // hour = h; minute = m; second = s;
18 //}
19 Time(int h = 0, int m = 0, int s = 0) : hour(h), minute(m), second(s){} //带参数初始化表的构造函数
20 void Set(int h, int m, int s);
21 void Show();
22 };
23
24 void Time::Set(int h, int m, int s)
25 {
26 hour = h; minute = m; second = s;
27 }
28 void Time::Show()
29 {
30 cout << hour << ":" << minute << ":" << second << endl;
31 }
32
33 int main()
34 {
35 Time t1;
36 t1.Show();
37 t1.Set(6, 18, 16);
38 t1.Show();
39
40 Time t2(12, 11, 10);
41 t2.Show();
42
43 return 0;
44 }