Problem Description
定义一个Tree(树)类,定义有成员ages(树龄),定义成员函数grow(int years)对ages加上years,定义 age()显示Tree对象的ages的值。
下面的定义程序不完整,请编程完善:
定义#include
定义Sample Output
using namespace std;
class Tree{
Tree t;
t.setages(3);
t.age();
t.grow(20);
t.age();
return 0;
}323
public: void grow(int years) { ages = ages + years; } void age() { cout << ages << endl; } void setages(int a) { ages = a; } int ages;
定义
作者:时尚