设计 Rectangle 类和实现两个普通函数,类中有两个成员变量和两个函数,其中成员变量的访问性为私有,函数的访问性为公有,具体要求如下:
高度:int height
宽度:int width
设置长方形的高和宽函数:void Set(int h, int w)
获取长方形的面积函数:int GetArea()
Rectangle GetRect(int h,int w)普通函数,h 、w 分别代表长方形的高宽,函数用来创建一个 Rectangle 对象并返回。
int GetRectArea(Rectangle rect)普通函数,函数用来获取 rect 对象的面积。
class Rectangle
{
public:
int height;
int width;
void Set(int h, int w);
int GetArea();
};
void Rectangle::Set(int h, int w)
{
this->height = h;
this->width = w;
}
int Rectangle::GetArea()
{
return this->height * this->width;
}
Rectangle GetRect(int h,int w)
{
Rectangle r;
r.height = h;
r.width = w;
return r;
}
int GetRectArea(Rectangle rect)
{
return rect.GetArea();
}