嘻唰唰第六批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; }
相关文章推荐
- 优先队列
- windows程序设计——飞机大战笔记(调用登陆数据库)
- OJ第六批——Problem B: A改错题--植物与花
- Play! 之各种Render
- HDU 5299 Circles Game
- cocos2dx自学之使用box2d物理世界
- JS的事件监听机制
- 如何破解海蜘蛛ISP6.1.5 极其isp运营商 v6.1.5
- Java内部类
- linux: 几个常用makefile模板
- hdu 5288 OO’s Sequence 2015 Multi-University Training Contest 1
- 队列
- [leedcode 152] Maximum Product Subarray
- Python CGi URL 中文以及特殊转义字符的处理
- ios Crash闪退日志获取和上传至服务器(NSSetUncaughtExceptionHandler)
- HDOJ 5289 Assignment 单调队列
- qt使用tab管理多个界面
- 未解——AndroidManifest.xml file missing!
- get传参如何传递数组
- 嘻唰唰第六批 A代码完善--系统日期