C++编程急啊。。。!!!!!

来源:百度知道 编辑:UC知道 时间:2024/09/24 01:41:34
设计一个矩形rectangle类,用户可以输入矩形的长和宽,计算矩形的周长和面积,并输出结果。用对象类对象的指针两种方式操作。

#include <iostream>
using namespace std;

class rectangle
{
private:
double length,width;
public:
rectangle(){length=0;width=0;};
rectangle(double a,double b):length(a),width(b){};
double area();
void set();
void setWidth(double w){width = w;}
void setLength(double l){length = l;}
double GetLength(){return length;}
double GetWidth(){return width;}
};

void rectangle::set()
{
double a,b;
cin>>a>>b;
setLength(a);
setWidth(b);
}

double rectangle::area()
{
return length*width;
}

void main()
{
rectangle r;
r.set();

cout<< r.area() <<endl;

}

#include <iostream>
#include <cstdlib>
using namespace std;

class Rectangle
{
private:
double w,h;
public:
Rectangle(