当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 定义一个带重载构造函数的日期类 代码参考

定义一个带重载构造函数的日期类 代码参考

2020年03月29日  | 移动技术网IT编程  | 我要评论

只有神知道的世界下载,联想旭日410l,麻元友

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 class date
 6 {
 7     private:
 8         int year;
 9         int month;
10         int day;
11     public:
12         date(){year=1900;month=1;day=1;}
13         date(int,int,int);
14         void show();
15         void init(int,int,int);
16 };
17 
18 date::date(int a, int b, int c)
19 {
20     year=a;
21     month=b;
22     day=c;
23 }
24 
25 void date::show()
26 {
27     cout<<year<<'-'<<month<<'-'<<day<<endl;
28     return;
29 }
30 
31 void date::init(int a, int b, int c)
32 {
33     year=a;
34     month=b;
35     day=c;
36     return;
37 }
38 
39 int main()
40 {
41     date d1,d2(2100,12,12);
42     int a,b,c;
43     cin>>a>>b>>c;
44     d1.show();
45     d2.show();
46     d1.init(a,b,c);
47     d1.show();
48     return 0;
49 }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网