嘻唰唰第六批B改错题
最新推荐文章于 2020-09-22 23:18:34 发布

haojy826 于 2015-07-21 18:36:13 发布
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
Description
注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交。
植物类具有属性id(编号)和name(名称),花类采用私有继承自植物类,增加新的属性Florescence(花期)。
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
class Plant
{
private:
int id;
string name;
public:
Plant(int id,string name):id(id),name(name) {}
void show()
{
cout<<id<<" "<<name;
}
};
class Flower:private Plant
{
private:
int Florescence; //花期
public:
Flower(int id,string name,int Florescence):Plant(id,name),Florescence(Florescence) {}
void show()
{
/*****修改的起始行******/
cout<<id<<" "<<name;
cout<<" "<<Florescence<<endl;
/*****修改的终止行*****/
}
};
int main()
{
int id,Florescence;
string name;
cin>>id>>name>>Florescence;
Flower f1(id,name,Florescence);
f1.show();
return 0;
}
Input
一种植物的编号,名称和花期
Output
该种植物的编号,名称和花期
Sample Input
5021 Peony 5
Sample Output
5021 Peony 5
代码:
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
class Plant
{
private:
int id;
string name;
public:
Plant(int id,string name):id(id),name(name) {}
void show()
{
cout<<id<<" "<<name;
}
};
class Flower:private Plant
{
private:
int Florescence;
public:
Flower(int id,string name,int Florescence):Plant(id,name),Florescence(Florescence) {}
void show()
{
Plant::show();
cout<<" "<<Florescence<<endl;
}
};
int main()
{
int id,Florescence;
string name;
cin>>id>>name>>Florescence;
Flower f1(id,name,Florescence);
f1.show();
return 0;
}
相关知识
花儿乐队:花季王朝+
花儿乐队
《花季王朝》28日发行 花儿乐队领你玩爽一夏
花儿乐队《花季王朝》签唱 人多势众千人捧场
零六盘点――文娱
花儿乐队:花龄盛会+亲笔签名版
古城亮灯年味足!揭阳古城以业态焕新打开发展新空间
17处花境“锦上添花” 园林式绿化“扮靓”城市主干道
花花节如“七”而至,勾勒多YOUNG自在生活
《花卉生产》课程获上海市中等职业学校 第六批市级在线开放课程建设立项
原文链接: 嘻唰唰第六批B改错题 https://m.huajiangbk.com/newsview105064.html
| 上一篇: js学习总结 | 下一篇: 字符串基础(C# 编程指南) |



