急!C++补充下面的程序,实现一个矩形类,计算矩形面积和周长?

输入格式
四个实数,表示矩形左下角和右上角坐标
输出格式
四行,每行一个数字,分别表示第一个矩形的周长和面积,两个矩形周长之和,两个矩形面积之和。要求保留两位小数
输入样例
1 1 2 2
输出样例
4.00
1.00
8.00
2.00
题目代码
#include <iostream>
#include <math.h>
#include<iomanip>

using namespace std;

class Rectangle{

public:
//在下面的空格声明 Rectangle 类的成员函数
____qcodep____

private:
//左下角坐标
double _x1;
double _y1;

//右上角坐标
double _x2;
double _y2;

//宽度和高度
double _width;
double _height;
};

//在下面的空格实现 Rectangle 类的成员函数

____qcodep____

int main(){

double x1, x2, y1, y2;
cin >>x1>>y1>>x2>>y2;
Rectangle r1(x1,y1,x2,y2);

Rectangle r2 = r1;

//在下面的空格按题目要求输出结果

____qcodep____

return 0;
}

就是说只用写几个函数就可以了对吧!建议看我给我好评哦,亲!
//声明
Rectangle(double x1,double y1,double x2,double y2);
Rectangle& operator=(const Rectangle& obj);
int GetLength();

int GetArea();

//实现
Rectangle::Rectangle(double x1,double y1,double x2,double y2) : _x1(x1),_y1(y1),_x2(x2),_y2(y2){
_width = x2 - x1;

_height = y2-y1;

}
Rectangle& operator=(const Rectangle& obj){
this._x1 = obj._x1;

this._y1 = obj._y1;
this._x2 = obj._x2;
this._y2 = obj._y2;
this._width = obj._width;
this._height = obj._height;
}
double Rectangle::GetLength(){ return 2*(_width + _height) ; }
double Rectangle::GetArea(){ return _width * _height ; }
//使用
cout<< fixed<<setprecision(2) << r1.GetLength() <<endl << r1.GetArea()<<endl
<< r1.GetLength() + r2.GetLength() <<endl
<< r1.GetArea() + r2.GetArea() <<endl;
温馨提示:答案为网友推荐,仅供参考
相似回答