题库 题库

【简答题】

试题八(15分,每空3分)
  阅读以下说明和C++程序,将应填入___(n)___处的字句写在答题纸的对应栏内。
[说明]
  下面程序的功能是计算并输出某年某月的天数。
[C++程序]
   #include<iostream>
  using namespace std;
  ___(1)___ Month{Jan,Feb,May,Jun,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 IsLeap Year(){
    return ((year % 4 == 0 && year % 100 != 0||year % 400==0);
   };
   Int CaculateDays(){
    Switch (___(3)___){
     Case Feb: {
      If (___(4)___)return29;
      else return28;
     }
     case Jan: case Mar: case May: case Jul: case Aug: case Oct:
     case Dec:return31:
     case Apr: case Jun: case Sep: case Nov: return30;
    }
   };
   Private:
   int year;
   Month month;
  };
  Void main (){
   Date day (2000,Fed);
   Cort << day.___(5)___();
  }

参考答案

(1) enum
(2) this->year
(3) month
(4) IsLeapYear()
(5) CaculateDays

相关试题