问答题
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12 Area is 0 Area is 12 注意:错误的语句在//********error********的下面,修改该语句即可。#include<iostream.h>class CRectangle{private: double length , width;public: CRectangle() { cout<<"Defaultconstructor.\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"<<length*width<<endl; } }; Void main() { CRectangle Rect1(3.0,4.0); //********error******** CRectangle Rect2(1); //********error******** CRectangle Rect3; Rect1.GetArea(); //********error******** Rect2.Set(0); Rect2.GetArea(); Rect3.GetArea();}
【参考答案】
正确答案:(1)CRectangle Rect2; (2)CRectangle Rect3(Rectl); (3)Rec......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)