声明一个Tree(树)类,有成员ages(树龄),成员函数grow(int years)用以对ages 加上years,showage( )用以显示tree对象的ages值。在主函数中定义Tree类对
//声明一个Tree(树)类,有成员ages(树龄),//成员函数grow(int years)用以对ages 加上years//,showage()用以显示tree对象的ages值。//在主函数中定义Tree类对象,并调用成员函数(学生自行指定实参数 #include<iostream>using namespace std;class Tree{public...
·
//声明一个Tree(树)类,有成员ages(树龄),
//成员函数grow(int years)用以对ages 加上years
//,showage()用以显示tree对象的ages值。
//在主函数中定义Tree类对象,并调用成员函数(学生自行指定实参数
#include<iostream>
using namespace std;
class Tree
{
public:
int grow(int years);
void showage();
private:
int ages;
};
int Tree::grow(int years)
{
cout << "输入树的树龄:" << endl;
cin >> ages;
ages = ages + years;
return ages;
}
void Tree::showage()
{
cout << "该树的年龄是:" << ages << endl;
}
int main()
{
Tree ages, years;
ages.grow(5);
ages.showage();
return 0;
}

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)