C++ 树类实现:定义树龄、生长和显示年龄
#include
class Tree { private: int ages; public: Tree(int years) { ages = years; } void Grow(int years) { ages += years; } void ShowAge() { cout << 'The age of the tree is ' << ages << ' years.' << endl; } };
int main() { Tree Pine(10); Pine.Grow(5); Pine.ShowAge(); return 0; }
原文地址: https://www.cveoy.top/t/topic/nyRO 著作权归作者所有。请勿转载和采集!