#include <cmath>
#include <iostream>
using namespace std;
class Point{
private:
double x,y;
public:
Point(int xx,int yy){x=xx;y=yy;}
double getX(){return x;}
double getY(){return y;}
};
class Rectangle{
private:
Point p1,p2;
public:
Rectangle(double x1,double y1,double x2,double y2):p1(x1,y1),p2(x2,y2){}
double calcArea() {return abs( (p1.getX()-p2.getX()) * (p1.getY()-p2.getY()) );}
};
int _tmain(int argc, _TCHAR* argv[])
{
Rectangle rect(1,1,5,5);
cout<<rect.calcArea()<<endl;
system("pause");
return 0;
}
【C++程序设计】P123_4-9 Rectangle类
最新推荐文章于 2022-04-06 21:01:55 发布