📄 li1005.cpp
字号:
//例10.5 定义日期类,利用构造函数初始化数据成员。
#include "date.h"
void main( )
{
Date d1; //自动调用构造函数 1
Date d2(2008); //自动调用构造函数 2
Date d3(2008, 10); //自动调用构造函数 3
Date d4(2008, 10, 6); //自动调用构造函数 4
d1.ShowDate( );
d2.ShowDate( );
d3.ShowDate( );
d4.ShowDate( );
}
/*
例10.5 的简化形式
#include <iostream.h>
class Date
{
int Year, Month, Day;
public:
Date(int y=2003, int m=1, int d=1) // 带参数缺省值的构造函数
{ Year=y; Month=m; Day=d; }
void ShowDate( )
{ cout <<Year<<'.'<<Month<<'.'<<Day<<endl; }
};
void main( )
{
Date d1, d2(2008), d3(2008, 10), d4(2008, 10, 6);
d1.ShowDate( );
d2.ShowDate( );
d3.ShowDate( );
d4.ShowDate( );
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -