//定义一个矩形类,数据成员包括左下角和右上角坐标,定义的成员函数包括必要的构造函数、输入坐标的函数,
//以及计算并输出矩形面积的函数。要求使用提示中给出的测试函数并不得改动。
#include <iostream>
using namespace std;
class Rectangle//矩形类
{
public:
Rectangle(){}
Rectangle(double a,double b,double c,double d):x(a),y(b),x1(c),y1(d){}
void input();
double area();
void output();
private:
double x;
double y;
double x1;
double y1;
};
void Rectangle::input()
{
cin>>x>>y>>x1>>y1;
}
double Rectangle::area()
{
double s;
s=(x1-x)*(y1-y);
return s;
}
void Rectangle::output()
{
cout<<area()<<endl;
}
int main()
{
Rectangle p1;
p1.input();
p1.output();
Rectangle p2(p1);
p2.output();
Rectangle p3(1,1,6,3);
p3.output();
return 0;
}
oj 2A
最新推荐文章于 2020-05-27 16:56:55 发布