首页 > 其它 > 题目详情
C++问题:设计一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算举行的面积
题目内容:
C++问题:设计一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算举行的面积优质解答
class Point{
protected:
double x;
double y;
public:
Point(double a,double b){x=a;y=b;}
Point(){x=0.0;y=0.0;}
double GetX(){return x;}
double GetY(){return y;}
};
class Rect{
protected:
Point p1;
Point p2;//p1是左下角,p2是右上角
public:
Rect(double i,double j,double,k,double l):p1(i,j),p2(k,l){}
double Area()
{return ((p2.GetX()-p1.GetX())*(p1.GetY()-p2.GetY()));}
};
//用于测试的主函数
void main()
{
Rect rect1(2,3,4,5);
cout
优质解答
protected:
double x;
double y;
public:
Point(double a,double b){x=a;y=b;}
Point(){x=0.0;y=0.0;}
double GetX(){return x;}
double GetY(){return y;}
};
class Rect{
protected:
Point p1;
Point p2;//p1是左下角,p2是右上角
public:
Rect(double i,double j,double,k,double l):p1(i,j),p2(k,l){}
double Area()
{return ((p2.GetX()-p1.GetX())*(p1.GetY()-p2.GetY()));}
};
//用于测试的主函数
void main()
{
Rect rect1(2,3,4,5);
cout
本题链接: