C++ 写一个简单的矩形类

#include<iostream>
using namespace std;
class Rectangle 
{
private:
	double x1,x2,y1,y2;

public:
	Rectangle(){
		x1=0;
		x2=0;
		y1=0;
		y2=0;
	}
 
	Rectangle (double a,double b, double c,double d)
	{
		x1=a;
		x2=c;
		y1=b;
		y2=d;

	}

	void outpub()
	{
		cout<<"面积: "<<((x2-x1)*(y2-y1))<<endl;
	}
	~Rectangle(){}
};

int main()
{
	Rectangle r1(1,1,100,100);
	r1.outpub();
		return 1;
}

猜你喜欢

转载自blog.csdn.net/laocooon/article/details/121674645