A改错题--植物与花

2020年1月17日 769点热度 0人点赞 0条评论

A改错题--植物与花

时间: 1ms        内存:128M

描述:

注:本题只需要提交标记为修改部分之间的代码,请按照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

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论