使用VC6打开考生文件夹下的工程test21_3,此工程包含一个源程序文件tes
使用VC6打开考生文件夹下的工程test21_3,此工程包含一个源程序文件test21_3.cpp,其中定义了用于表示长方形的类CRectangle,但类CRectangle的定义并不完整。请按要求完成下列操作,将类CRectangle的定义补充完整。 (1)定义CRectangle的构造函数,函数含参数dx,dy,da和db,它们都是double型的数据,请将类数据成员x,y, a和b初始化,并输出“CRectangleConstructe
D、”(另起一行输出该文字)。请在注释“//**1**之后添加适当的语句。 (2)完成类CRectangle的成员函数getperimeter()的定义,将以a和b为边的矩形周长的值返回,请在注释“//**2**”之后添加适当的语句。 (3)完成类CRectangle的成员函数getarea()的定义,将以a和b为边的矩形面积的值返回,请在注释“//**3**”之后添加适当的语句。 (4)完成类CRectangle的友元函数friend double distCRectangle& rt)的定义,先定义两个double型的临时变量tx和ty,然后将参数对象rt的数据成员x与a的一半相加,y与b的一半相加,分别赋值给tx和ty,最后求出tx与ty的平方和的值之后将它的平方根返回,将请在注释“//**4**”之后添加适当的语句。 输出结果如下:CRectangleConstructe
D、Down_Left corner point is:(100,50) a=1200,b=700 Perimeter of this rectangle is:3800Area of this rectangle is:840000 TheDistance is:806.226CRectangleConstructe
D、Down_Left corner point is:(200,150) a=2000,b=800 Perimeter of this rectangle is:5600Area of this rectangle is:1.6e+006 TheDistance is:1320.04CRectangleDestructe
D、CRectangleDestructe
D、 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件test21_3.cpp清单如下: #include<iostream.h> #include<math.h> classCRectangle { private:double x;double y;double a;double b; public: CRectangle(){cout<<"\nCRectangleConstructe
D、"<<endl;} CRectangle(double dx, double dy, double da, double db){ //**1** a=da; b=db; cout<<"\nCRectangleConstructe
D、"<<endl;}~CRectangle ( ){cout<<"CRectangleDestructe
D、"<<endl;}void putxy(double dx, double dy){ x=dx; y=dy;}void putab(double da, double db)( a=da; b=db;}double getx(){ return x;}double gety(){ return y;}double geta(){ return a;}double getb(){ return b;}double getperimeter() { //**2** }double getarea() { //**3** }friend double distCRectangle& rt); }; double distCRectangle& rt) {//**4** ty=rt.y+rt.b/2.0;return sqrt(tx*tx+ty*ty); } void main() { CRectangle rect;rect.putxy(100.0, 50.0);rect.putab(1200.0, 700.0);cout<<"Down_Left corner point is: ("<<rect.getx() <<", "<<rect.gety()<<")" <<endl;cout<<"a= "<<rect.geta()<<", b="<<rect.getb() <<endl;cout<<"Perimeter of this rectangle is: "<<rect.getperimeter()<<endl;cout<<"Area of this rectangle is:"<<rect.getarea()<<endl;cout<<"TheDistance is:"<<dist(rect)<<endl; CRectangle recta(200,150,2000,800);cout<<"Down_Left corner point is:("<<rect
A、getx()<<","<<rect
A、gety()<<")"<<endl;cout<<"a="<<rect
A、geta()<<", b="<<rect
A、getb()<<endl;cout<<"Perimeter of this rectangle is: "<<rect
A、getperimeter()<<endl;cout<<"Area of this rectangle is: "<<rect
A、getarea()<<endl;cout<<"TheDistance is :"<<dist(recta)<<endl; }