当前位置: 当前位置:首页 > 休闲 > Problem F: 定义Tree类 正文

Problem F: 定义Tree类

2024-05-02 18:02:27 来源:口口声声网 作者:休闲 点击:798次

Problem F: 定义Tree类

 

Problem Description

定义一个Tree(树)类,定义有成员ages(树龄),定义成员函数grow(int years)对ages加上years,定义 age()显示Tree对象的ages的值。

下面的定义程序不完整,请编程完善:

定义

#include
using namespace std;
class Tree{
    Tree t;
    t.setages(3);
    t.age();
    t.grow(20);
    t.age();
    return 0;
}

定义Sample Output
323
public:	void grow(int years)	{		ages = ages + years;	}	void age()	{		cout << ages << endl;	}	void setages(int a)	{		ages = a;	}	int ages;

 

定义
作者:时尚
------分隔线----------------------------
头条新闻
图片新闻
新闻排行榜