C++构造函数编程

来源:百度知道 编辑:UC知道 时间:2024/09/24 22:26:15
定义并实现一个矩形类,有长、宽两个属性,用成员函数计算矩形的面积

class Rectangle
{
public:
Rectangle(double wid , double hei = 0.0):width(wid), height(hei){}

//求面积的成员函数
double area(int width, int height)
{
return width * height;
}
private:

double width;//宽
double height;//长
};