Sample Input
3.7 0.4 6.5 4.9
Sample Output
12.6
12.6
10
/* All rights reserved.
* 文件名称:test.cpp
* 作者:陈丹妮
* 完成日期:2015年 6 月 21 日
* 版 本 号:v1.0
*/
#include <iostream>
#include <cmath>
using namespace std;
class Rectangle
{
private:
double x1;
double y1;
double x2;
double y2;
public:
Rectangle(double a1=1,double b1=1,double a2=6,double b2=3):x1(a1),y1(b1),x2(a2),y2(b2) {}
Rectangle(Rectangle &p);
void input();
void output();
};
void Rectangle::input()
{
cin>>x1>>y1>>x2>>y2;
}
void Rectangle::output()
{
double s;
s=abs(x2-x1)*abs(y2-y1);
cout<<s<<endl;
}
Rectangle::Rectangle(Rectangle &p)
{
x1=p.x1;
y1=p.y1;
x2=p.x2;
y2=p.y2;
}
int main()
{
Rectangle p1;
p1.input();
p1.output();
Rectangle p2(p1);
p2.output();
Rectangle p3(1,1,6,3);
p3.output();
return 0;
}
心得体会:这个还是比较简单,继续努力,刷题刷题!!!
第十五周oj刷题——Problem B: 矩形类定义【C++】
原文:http://blog.csdn.net/nufangdongde/article/details/46581369