关于C++的问题,高手进!
来源:百度知道 编辑:UC知道 时间:2024/09/22 04:34:40
2、声明一个tree(树)类,有成员ages(树龄),成员函数grow(int years)对ages加上years,age()显示tree对象的ages的值
class rectangle
{
private:
float width;
float height;
public:
rectangle(float w,float h):width(w),height(h){}//构造函数
float area(){return width*height;}
};
2、、、、、、、、、、、、、、、、、、、
class tree
{
private :
int ages;
public:
int grow(int years){return ages+years;}
int age(){return ages;}
};
class rectangle
{
private:
float width;
float height;
public:
float area(){return width*height;}
};
class tree
{
private :
int ages;
public:
int grow(int years){return ages+years;}
int get_ages(){return ages;}
};
//////////////////////////
晕。忘构造函数了。见烟花飘飘
1、
class rectangle
{
private:
float width; //宽
float height;//长
public:
rectangle(float w,float h):width(w),height(h){}//构造函数
float area(){return width*height;} //计算面积的成员函数
}; <