【C++程序设计】P123_4-9 Rectangle类

来源:互联网 发布:数学公式编辑器 知乎 编辑:程序博客网 时间:2024/05/16 09:09
#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;}

原创粉丝点击