请使用”答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2,本程序中有两个类:一是日期类(Date),用于表示一天的日期(年、月、日);另一个是截止日期类(Dead-line),用于表示一个任务的截止日期,超过该日期即为超时。Deadline

admin2020-06-29  24

问题 请使用”答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2,本程序中有两个类:一是日期类(Date),用于表示一天的日期(年、月、日);另一个是截止日期类(Dead-line),用于表示一个任务的截止日期,超过该日期即为超时。Deadline类中有Date类的数据成员。这里对Deadline类的数据成员和成员函数做一下说明:
    int id;//截止日期的id
    Date end_date;//截止日期,表示允许完成该任务的最后一天
  void finish(Date date);//date未超过截止日期时,输出"Finished!t",否则输出"Time out."
bool check(Date date);//date未超过截止日期时返回true,否则返回false。
    程序正确情况下输出:
    Finished!
    Time out.
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“//**********found**********”。
1  #include
2  using namespace std;
3  class Date{
4  private:
5    int year;
6    int month;
7    int day of month;
8  public:
9  Date(int y,int m,int d){
10  this->year=y;
11  this->month=m;
12  this->day_of_month=d;
13    }
14    bool operator<=(Date&dt)const{
15    if(this->yearyear==dt.year&&this->monthyear==dr.year&&this->month==dt.month&&this->day_of_month<=dt.day_of_month))
16    //**********found**********
17    _____;
18    return false;
19   }
20  };
21  class Deadline{
22  private:
23    int id;
24    Date end_date;
25   public:
26    Deadline(int id,int year,int month,int day_of month)
27    // **********found**********
28    _____
29    {
30    this->id=id;
31    }
32    void finish(Date date){
33    if(check(date))
34    //**********found**********
35    cout<<______<36    else
37    cout<<"Time out."<38    }
39    bool check(Date date){
40    //**********found**********
41    return______;
42    }
43  };
44  int main(){
45    Deadline*d1=new Deadline(1,2014,3,12);
46    Deadline*d2=new Deadline(2,2013,12,2 0);
47    Date current time(2014,1,1);
48    d1->finish(current time);
49    d2->finish(current time);
50    delete d1;
51    delete d2;
52    return 0;
53    }

选项

答案(1)retum true (2):end_date(year,month,day_of_month) (3)"Finshed" (4)(end_date<=date)?false:true

解析 (1)根据题设可知比较两个日期的大小,由if语言的判断,可知this的日期大于date,返回真。
    (2)构造函数的初始化列表,使用基类的构造函数完成子类成员的初始化。
    (3)根据题意可知,没有超过deadline,故输出"Finshed"。
    (4)检查当前日期是否超过截止时间。超过deadline,返回false,否则返回true。
转载请注明原文地址:https://kaotiyun.com/show/Poyp777K
0

最新回复(0)