【C++程序】
#include<iostream>
using namespace std;
(1) MonthJan,Feb,Mar,Art,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec;
class Date
public:
Date(int year,Month m_month)
(2) =year;
if (m_month<Jan‖m_month>Dec) month=Jan;
else month=m_month;
;
~Date();
bool IsLeapYear()
return ((year%4==0 && year%1001!=0)‖year%400==0);
;
int CaculateDays()
switch( (3) )
case Feb:
if( (4) )return29;
e1Se return 28;
case Jan:case Mar:case May:case Jul:case AUg:case Oct:
case Dec:retllrn 31;
case Apr:case Jun:Case Sep:case Nov:roturu30;
;
private:
int year;
Month month;
;
void main()
Date day(2000,Feb);
tout<<day. (5) ();
参考答案:(1)enum
(2)this->year
(3)month
(4)IsLeapYear()
(5)Cacu lateDays
解析:
[分析]:
程序的空(1)所在行的目的是定义一枚举类型用来表示一年12个月,所以空1应填上enum;在类Data中定义了两个私有变量year和m_month分
别用来存储年份和月份,在Data类的构造函数中,要求给出年份和月份来构造一个Data类的对象,因为构造函数中参数名称和私有变量的名称
相同,为了在构造函数中使用私有变量year,必须加上 this指针,所以空(2)应填上this->year。
函数CaculateDays用宋计算某一年某个月的天数,不论是否是闰年,除2月份以外,所有的大月都是31天,小月都是30天;如果是闰年,2
月份是29天,否则是28天。根据分析,空(3)应填上m month用来判断月份是大月、小月或者二月,空(4)用来判断是否是闰年,调用函数
IsLeapYear()即可得到结果。