问答题
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12 Area is 0 Area is 12 注意:错误的语句在∥********error********的下面,修改该语句即可。 #include
class CRectangle { private: double length,width; public: CRectangle() { cout<<“Default constructor.\n”; } CRectangle(double 1,double w) { length=1;width=w; cout<<“Constructor.\n”; } void Set(double 1,double W) this一>length=1; this一>width=w; } void GetArea() { cout<<“Area is”<
【正确答案】
正确答案:(1)CRectangle Rect2; (2)CRectangle Rect3(Rectl); (3)Rect2.Set(0,0);
【答案解析】
解析:程序中定义了类CRectangle,有length和width两个成员变量,两个构造函数,Set()成员函数和GetArea()成员函数,Set()成员函数可以改变length和width的值,GetArea()成员函数在屏幕上打印length和width的积。
提交答案
关闭