设计并测试一个名为Rectangle 的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。

  • Post author:
  • Post category:其他


#include <iostream>
#include <cmath>
using namespace std;
class Rectangle
{
    int x1,y1,x2,y2;
public:
    void setx1(int x1);
    void sety1(int y1);
    void setx2(int x2);
    void sety2(int y2);
    int getx1();
    int gety1();
    int getx2();
    int gety2();

};

void Rectangle::setx1(int x1)
{
    this->x1=x1;
    return;
}

void Rectangle::sety1(int y1)
{
    this->y1=y1;
    return;
}

void Rectangle::setx2(int x2)
{
    this->x2=x2;
    return;
}

void Rectangle::sety2(int y2)
{
    this->y2=y2;
    return;
}
/*
int Rectangle::getx1()
{
    return x1;
}
int Rectangle::gety1()
{
    return y1;
}
int Rectangle::getx2()
{
    return x2;
}
int Rectangle::gety2()
{
    return y2;
}
*/
int main()
{
    Rectangle r;
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    r.setx1(x1);
    r.sety1(y1);
    r.setx2(x2);
    r.sety2(y2);
    /*
    r.getx1(x1);
    r.gety1(y1);
    r.getx2(x2);
    r.gety2(y2);
    */
    float s;
    s=(x2-x1)*(y2-y1);
    cout<<s<<endl;
    return 0;
}



版权声明:本文为qq_45748133原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。