OJ24

#include <iostream>

using namespace std;

class Rectangle
{

public:
    Rectangle() {};
    Rectangle(Rectangle &r)
    {
        *this=r;
    }

    Rectangle (double a,double b,double c,double d):x1(a),y1(b),x2(c),y2(d) {}

    void input()
    {
        cin>>x1>>y1>>x2>>y2;
    }
    Rectangle operator+(Rectangle&);
    friend ostream & operator<<(ostream&,Rectangle&);

private:
    double x1;
    double y1;
    double x2;
    double y2;
};


Rectangle  Rectangle :: operator+ (Rectangle&r1)
{
    Rectangle r;
    r.x1=x1+r1.x1;
    r.y1=y1+r1.y1;
    r.x2=x2+r1.x2;
    r.y2=y2+r1.y2;
    return r;

}
ostream & operator<<(ostream&out ,Rectangle&r)
{

    out<<((r.x2-r.x1)*(r.y2-r.y1))<<endl;
    return out;

}

int main()

{

    Rectangle p1(1,1,6,3),p2,p3;

    p2.input();

    p3=p1+p2;

    cout<<p3;

    return 0;

}

 

//提交时请加上主函数。


 

阅读更多

没有更多推荐了,返回首页