YTU-OJ-Problem B: A改错题--植物与花

Problem B: A改错题--植物与花

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 205   Solved: 135
[ Submit][ Status][ Web Board]

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

HINT

#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;
}


你可能感兴趣的:(C++)