# 熟悉题型——类设计（ 矩形类定义【C++】）

``3.7 0.4 6.5 4.9``

``````12.6
12.6
10
``````

``````#include<iostream>
using namespace std;
class Rectangle
{
public:
Rectangle()
{}
Rectangle(double q,double w,double e,double r):x1(q),y1(w),x2(e),y2(r)
{}
void input()
{
cin>>x1>>y1>>x2>>y2;
}
void output()
{
cout<<(x2-x1)*(y2-y1)<<endl;
}
private:
double x1,x2,y1,y2;
};

int main()

{

Rectangle p1;

p1.input();

p1.output();

Rectangle p2(p1);

p2.output();

Rectangle p3(1,1,6,3);

p3.output();

return 0;

}
``````

``````#include<iostream>
using namespace std;
class Rectangle
{
private:
double x1,x2,y1,y2;
public:
Rectangle();
Rectangle(double,double,double,double);
void input();
void output();
};
Rectangle::Rectangle()
{
x1=x2=y1=y2=0;
}
Rectangle::Rectangle(double x,double y,double m,double n):x1(x),y1(y),x2(m),y2(n){}
void Rectangle::input()
{
cin>>x1>>y1>>x2>>y2;
}
void Rectangle::output()
{
cout<<(x1-x2)*(y1-y2)<<endl;
}
int main()

{

Rectangle p1;

p1.input();

p1.output();

Rectangle p2(p1);

p2.output();

Rectangle p3(1,1,6,3);

p3.output();

return 0;

}
``````