使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12

admin2017-09-20  25

问题 使用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”<width<    }
};
void main()
{
    CRectangle Rectl(3.0,4.0);
    ∥********error********
    CRectangle Rect2(1);
    ∥********error********
    CRectangle Rect3;
    Rectl.GetArea();
  ∥********error********
    Rect2.Set(0);
    Rect2.GetArea();
    Rect3.GetArea();
}

选项

答案(1)CRectangle Rect2; (2)CRectangle Rect3(Rectl); (3)Rect2.Set(0,0);

解析 程序中定义了类CRectangle,有length和width两个成员变量,两个构造函数,Set()成员函数和GetArea()成员函数,Set()成员函数可以改变length和width的值,GetArea()成员函数在屏幕上打印length和width的积。
转载请注明原文地址:https://kaotiyun.com/show/ATAp777K
0

最新回复(0)