问答题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【说明】
下面程序的功能是计算并输出某年某月的天数,函数IsLeap Year()能够判断是否是闰年。
【C++程序】
# include < iostream >
using namespace std;
{{U}}(1) {{/U}} Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
class Date {
public:
Date( int year, Month m_ month) {
this→year = year;
if( {{U}}(2) {{/U}}) month: Jan;
else month = m_ month;
};
~Date(){};
bool IsLeap Year( ) {
return ((year%4= =0 &&year% 100 ! =0)|| year%400= =0);
};
int CaculateDays( ) {
switch(m_month ) {
case {{U}}(3) {{/U}};{
if {{U}}(4) {{/U}}return 29;
else return 28;
}
case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec: return 31;
case Apr: case Jun: case Sop: case Nov: return 30;
}
}
private:
int year;
Month month;
};
void main( ) {
Date day(2000,Feb);
cout < <day.{{U}} (5) {{/U}}( );
}
问答题
【正确答案】
【答案解析】
问答题
【正确答案】
【答案解析】m_ month<Jan||m_ month>Dec [解析] 当输入参数m_ month不合法时,将私有变量初始化为Jan。
问答题
【正确答案】
【答案解析】Feb [解析] 只有2月即不是30天也不是31天,需要单独处理。
问答题
【正确答案】
【答案解析】IsLeapYear() [解析] 判断该年是否是闰年,闰年时2月有29天,否则28天。
问答题
【正确答案】
【答案解析】CaculateDays [解析] 计算本月天数并输出,这里填入函数CaculateDsye()。