欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

设计MyTime类 代码参考

程序员文章站 2022-06-22 09:26:16
1 #include 2 #include 3 4 using namespace std; 5 6 class MyTime 7 { 8 private: 9 int hour; 10 int minute; 11 int second; 12 public ......
 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 }