OJ嘻唰唰之改错题(3)植物与花

问题及代码
/*
*Copyright(c)2014,烟台大学计算学院
*All  rights reserved.
*文件名称:test.cpp
*作者:陈银丽
*完成日期:2015年7月4日
*版本号:v1.0
*
*问题描述:
*输入描述:
 存在错误的程序行列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;
        /*****修改的终止行*****/
    }
};


*程序输出:
*/

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

运行结果:


知识点总结:考点是继承与派生。这道题是私有继承。私有基类的私有成员在派生类中成为不可访问的成员,只有基类的成员函数可以引用他们。所以,在这道题中的id变成了不可访问的,

学习心得:关于继承与派生的概念理论也要熟悉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值