您的位置:首页 > 其它

嘻唰唰第六批B改错题--植物与花

2015-07-21 18:36 405 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: