精选问答
设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算矩形的面积.要求表示矩形的两点坐标用类表示. 是关于C++的一道题目.

2019-04-19

设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算矩形的面积.
要求表示矩形的两点坐标用类表示. 是关于C++的一道题目.
优质解答
#include
class Point
{private:
double x,y;
public:
Point(double xx,double yy){x=xx;y=yy;}
double getX(){return x;}
double getY(){return y;}
};
class Rectangle
{ private:
Point Leftdown,Rightup;
public:
Rectangle(double x1,double y1,double x2,double y2):LeftDown(x1,y1),Rightup(x2,y2){}
double Area(){return (Rightup.getX()-Leftdown.getX())*(Rightup.getY()-Leftdown.getY());}
};
void main()
{ Rectangle r(1.0,1.5,2.0,3.3);
cout
#include
class Point
{private:
double x,y;
public:
Point(double xx,double yy){x=xx;y=yy;}
double getX(){return x;}
double getY(){return y;}
};
class Rectangle
{ private:
Point Leftdown,Rightup;
public:
Rectangle(double x1,double y1,double x2,double y2):LeftDown(x1,y1),Rightup(x2,y2){}
double Area(){return (Rightup.getX()-Leftdown.getX())*(Rightup.getY()-Leftdown.getY());}
};
void main()
{ Rectangle r(1.0,1.5,2.0,3.3);
cout
相关问答