测试一个名为Retangle的矩形类,并计算该矩形类的面积
设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积我自己写的程序请高手指点
#include "iostream.h"
#include "math.h"
class Point
{
public:
Point(int xx=0,int yy=0){X=xx;Y=yy;}
Point(Point &p);
int GetX() {return X;}
int GetY() {return Y;}
private:
int X,Y;
};
Point::Point(Point &p)
{
X=p.X;
Y=p.Y;
}
class Rectangle
{
public:
Rectangle(Point xp1,Point xp2);
double GetDis(){return dist;}
private:
Point p1,p2;
double dist;
};
Rectangle::Rectangle(Point xp1,Point xp2)
:p1(xp1),p2(xp2)
{
double x=double(p1.GetX()-p2.GetX());
double y=double(p1.GetX()-p2.GetY());
dist =sqrt(x*x+y*y);
}
void main ()
{
Point myp1(4,7),myp2(9,5);
Rectangle myd(myp1,myp2);
cout <<"The area is:";
cout <<myd.GetDis()<<endl;
}