题目内容
阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。
【说明】
本程序的功能是根据矩形左上角和右下角顶点坐标生成一个矩形对象,然后输出该矩形4个顶点的坐标,计算并输出该矩形的面积。
【C++代码】
include<iostream>
using namespace std;
class MyPoint(//表示平面坐标系中的点的类
double x;
double y;
public:
MyPoint (double x,double y){this->x=x;this->y=y;}
double getX()const{(1);}
double getY()const{ return y;}
void show()const{ cout<<'('<<x<<','<<y<<')';}
};
class MyRectangle{ //表示矩形的类
MyPoint upleft; //矩形的左上角顶点
MyPoint down right; //矩形的右下角顶点
public:
MyRectangle(MyPoint upleft,MyPoint downright);
MyPoint getUpLeft()const{return up_left;} //返回左上角坐标
MyPoint getDownRight()const{return down_right;} //返回右下角坐标
MyPoint getUpRight()const; //返回右上角坐标
MyPoint getDownLeft()const; //返回左下角坐标
double area()const; //返回矩形的面积
};
MyRectangle:: MyRectangle((2)):
up left(p1),down_right(p2){}
MyPoint MyRectangle::getUpRight()const
{
return MyPoint(down_right.getX(),up_left.getY());
}
MyPoint MyRectangle::getDownLeft()const
{
return MyPeint((3));
}
double (4) ::area()const
{
return (getUpLeft(),getX()-getDownRight().getX())*
(getDownRight().getY()-getUpLeft().getY());
}
int main()
{
MyRectangle r(MyPoint(0,2),MyPoint(2,0));
r.getUpLeft(),show();
r.getUpRight().show();
r.getDown Right().show();
(5);
cout<<r.area()<<end1;
return 0;
}
查看答案
搜索结果不匹配?点我反馈