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<<rect1.Area()<<endl;
}
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<<rect1.Area()<<endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询