定义一个Tree(树)类,有成员ages(树龄),成员函数grow(int years)对ages加上years,age()显示tree对象的ages的值。
生活随笔
收集整理的這篇文章主要介紹了
定义一个Tree(树)类,有成员ages(树龄),成员函数grow(int years)对ages加上years,age()显示tree对象的ages的值。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include
using namespace std;
class Tree
{
public:
int grow(int years);
void age();
private:
int ages;
};
int Tree::grow(int years)
{
cout << “輸入樹的樹齡:”;
cin >> ages;
ages = ages + years;
return ages;
}
void Tree::age()
{
cout << “樹的年齡為:” << ages << endl;
}
int main()
{
Tree ages;
int i;
cout << “輸入樹的年份:”;
cin >> i;
ages.grow(i);
ages.age();
}
總結
以上是生活随笔為你收集整理的定义一个Tree(树)类,有成员ages(树龄),成员函数grow(int years)对ages加上years,age()显示tree对象的ages的值。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python用socket、多线程实现一
- 下一篇: 在linux中安装google拼音输入法