问答题
请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1。此工程中包括类Date(“日期”)和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
2006-1-1
2005-12-31
2005-12-31
2006-1-1
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
using namespace std;
class Date {
public:
Date(int y=2006, int m=1, int d=1)
// ERROR ********* found*********
: year=y, month=m, day=d
{}
/ERROR ********* found*********
Date (const Date d)
{
this->year=d.year;
this->month=d.month;
this->day=d.day;
}
void print () const
{
cout << year << ’-’ << month <<’-’<< day << endl;
}
private:
//ERROR ********* found*********
int year (2006), month(1), day(1);
};
int main ()
{
Date d1, d2 (2005, 12, 31), d3;
d1.print ();
d2.print();
d3=d2;
d2=d1;
d1=d3;
d1.print();
d2.print();
return 0;
}
【参考答案】
(1):year(y),month(m),day(d) (2)Date(const Date&d) (3)int yea......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)