#include<iostream>
using namespace std;
class Rectangle
{public:
Rectangle();//因为没有定义int的原因是看main里面的函数,这个函数没有返回值;
Rectangle(const Rectangle&p);//因为没有定义int的原因是看main里面的函数,这个函数没有返回值;
Rectangle(double,double,double,double);//因为没有定义int的原因是看main里面的函数,这个函数没有返回值;
void input()//输入;
{
cin>>x1>>y1>>x2>>y2;
}
void output()//输出;
{
cout<<(x2-x1)*(y2-y1)<<endl;
}
private:
double x1,x2,y1,y2;
double s;
};
Rectangle::Rectangle(const Rectangle&p)//复制构造函数;
{
x1=p.x1;x2=p.x2;y1=p.y1;y2=p.y2;
}
Rectangle::Rectangle()
{
x1=0,x2=0,y1=0,y2=0;
}
Rectangle::Rectangle(double a, double b, double c,double d)//直接输入的;
{
x1=a;
y1=b;
x2=c;
y2=d;
}
int main()
{
Rectangle p1;
p1.input();
p1.output();
Rectangle p2(p1);
p2.output();
Rectangle p3(1,1,6,3);
p3.output();
return 0;
}
矩形类定义C++
最新推荐文章于 2024-08-16 07:15:00 发布