使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。 (1)定义私有数据成员leftPoint、topPoint、rightP

admin2017-09-20  19

问题 使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。
  (1)定义私有数据成员leftPoint、topPoint、rightPoint、bottomPoint,分别用于表示矩形左上角及右下角的点的坐标,它们都是double型的数据。请在注释∥********1********之后添加适当的语句。
    (2)完成默认构造函数CRect的定义,指定缺省实参为0,都是double型的数据。请在注释∥********2********之后添加适当的语句。
    (3)定义函数体为空的析构函数。请在注释∥********3********之后添加适当的语句。
    (4)在main()函数中定义CRect类的实例rect2,并把rect1  的值赋给rect2。  请在注释∥********4********之后添加适当的语句。
    注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
#include
Class CRect
{
private:
∥********1********
public:
∥********2********
∥********3********
    void SetPoints(double,
double,double,double);
    void SetLeftPoint(double m){leftPoint=m;)
    void SetRightP0int(double m){  rightPoint=m;)
    void SetTopPoint(double m){topPoint=m;)
    void SetBottomPoint(double m){bottomPoint=m;)
    void Di splay();
};
CRect::CRect(double 1,double
t,double r,double b)
{
    leftPoint=1;topPoint=t;
    rightPoint=r;bottomPoint
=b;
}
void CRect::SetPoints(double
1,double t,double r,double b)
{
    leftPoint=1;topPoint=t;
    rightPoint=r;bottomPoint
=b;
}
void CRect::misplay()
{
    cout<<“left—top point iS
(”<<1eftPoint<<“,”<    cout<<”right—bottom point is
(”<nt<<¨)¨<<’\n’;
}
void msin(){
    CReCt rect0;
    rect0.Di splay();
    rect0.SetPointS(20,20.6,30,4 0);
    rect0.Display();
    CRect rectl(0,0,150,150);
    rectl.SetTopP0int(10.5);
    rectl.SetLeftPoint(10.5);
   ∥********4********
    rect2.Di splay();
}

选项

答案(1)添加语句:double leftPoint,topPoint,rightPoint,bottomPoint; (2)添加语句:CRect(double leftPoint=0,double topPoint=0,double rightPoint=0,double bottomPoint=0); (3)添加语句:~CRect(){); (4)添加语句:CRect rect2(rectl);

解析 程序中定义了一个表示矩形的类CRect,该类中定义了私有数据成员leftPoint、topPoint、rightPoint、bottomPoint,分别用于表示矩形左上角及右下角的点的坐标且它们的数据类型都是double型,类CRect有多个成员函数,SetPoints(),SetLefiPoint0函数可改变成员变量leftPoint的值,而SetRightPoint()成员函数可改变rightPoint的值,SetTopPoint0可改变topPoint的值,SetBottomPoint()改变bottomPoint的值,Display()成员函数显示成员变量的值。
转载请注明原文地址:https://kaotiyun.com/show/5TAp777K
0

随机试题
最新回复(0)