其他分享
首页 > 其他分享> > 设计MyTime类 代码参考

设计MyTime类 代码参考

作者:互联网

 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 class MyTime
 7 {
 8     private:
 9         int hour;
10         int minute;
11         int second;
12     public:
13         void SetTime(){cin>>hour>>minute>>second;return;}
14         void print_12();
15         void print_24();
16 };
17 
18 void MyTime::print_12()
19 {
20     if(hour<12)
21     {
22         printf("%02d:%02d:%02d AM\n",hour,minute,second);
23     }
24     else
25     {
26         printf("%02d:%02d:%02d PM\n",hour-12,minute,second);
27     }
28     return;
29 }
30 
31 void MyTime::print_24()
32 {
33     printf("%02d:%02d:%02d\n",hour,minute,second);
34     return;
35 }
36 
37 int main()
38 {
39     MyTime one;
40     one.SetTime();
41     one.print_12();
42     one.print_24();
43     return 0;
44 }

 

标签:12,hour,参考,int,代码,MyTime,print,void
来源: https://www.cnblogs.com/Conan-jine/p/12588156.html