第四章课后练习
习题
4-14题目:定义一个Tree类,有成员树龄ages,成员函数grow对ages加上years,age()显示tree对象的ages对象的ages的值。
代码部分:
#include<iostream> using namespace std; class Tree { private: int ages; public: Tree(int a) { ages = a; } void grow(int years) { cout << ages + years; } }; int main() { int a; cin >> a; Tree x(a); x.grow(3); return 0; }