C++ Tree类

来源:互联网 发布:ug编程基础 编辑:程序博客网 时间:2024/04/27 13:52
#include<iostream>using namespace std;class Tree{public:    Tree(int ages){ _ages = ages; }    ~Tree();    void grow(int years){ _ages += years; }    void age();private:    int _ages;};void Tree::age(){    cout << "这棵树的年龄是:" << _ages << endl;}int main(){    int treeage;    Tree thetree(7);    thetree.age();    thetree.grow(100);    thetree.age();    cout << "请输入成长又经历的时间:";    cin >> treeage;    Tree smalltree(treeage);    smalltree.age();    smalltree.grow(treeage);    smalltree.age();    return 0;}
0 0