题目描述
注:本题只需要提交标记为修改部分之间的代码,请按照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;
}
输入
一种植物的编号,名称和花期
输出
该种植物的编号,名称和花期
样例输入
5021 Peony 5
样例输出
5021 Peony 5
参考代码
#include <stdio.h>
int main()
{
char c[99];
gets(c);
puts(c);
return 0;
}
解析
暂无