OJ26

//定义一个矩形类,数据成员包括左下角和右上角坐标,
//定义的成员函数包括必要的构造函数、输入坐标的函数,以及计算并输出矩形面积的函数。
//要求使用提示中给出的测试函数并不得改动。

#include <iostream>

using namespace std;
class Coordinate
{
public:
    double x,y;
    Coordinate(){}
    Coordinate(double xx,double yy):x(xx),y(yy){}
};
class Rectangle:public Coordinate
{
private:
    Coordinate left,right;
public:
    Rectangle(){}
    Rectangle(double lx,double ly,double rx,double ry):left(lx,ly),right(rx,ry){}
    Rectangle(Rectangle&r)
    {
        *this=r;
    }
    void input()
    {
        cin>>left.x>>left.y>>right.x>>right.y;
    }
    void output()
    {
        cout<<((right.x-left.x)*(right.y-left.y))<<endl;
    }
};
int main()
{
    Rectangle p1;
    p1.input();
    p1.output();
    Rectangle p2(p1);
    p2.output();
    Rectangle p3(1,1,6,3);
    p3.output();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值