5.13

#include <iostream>

using namespace std;

class Tree {

private:

    int ages;

public:

    Tree(int ages=0):

        ages(ages){}

    void grow(int years) {

        ages += years;

    }

    int getAges()const {

        return ages;

    }

 

};

int main() {

    Tree tree(10);

    tree.grow(5);

    cout << "The ages of the tree is:" << tree.getAges() << endl;

}

 

posted @ 2023-05-13 23:39  刘梦磊  阅读(27)  评论(0)    收藏  举报