6月11号作业

思维导图

#include <iostream>
using namespace std;
class Animal
{
private:
    string name;
public:
    Animal(){}
    Animal(string name):name(name)
    {
        //cout << "Animal;有参" << endl;
    }
    virtual void perform()
      {
          cout << "讲解员的名字是: " << name << endl;
      }
};
class Sun:public Animal
{
private:
    string lion;//狮子
    string Elephant;//大象
    string monkey;//猴子
public:
    Sun()
    {

    }
    Sun(string lion,string Elephant,string monkey,string name):Animal(name),lion(lion),Elephant(Elephant),monkey(monkey)
    {
       // cout << ""
    }
    void perform()
    {
        Animal::perform();
        cout << "狮子的名字叫: " << lion << endl;
        cout << "大象的名字叫: " << Elephant << endl;
        cout << "猴子的名字叫: " << monkey << endl;
    }
};
class Conservator:public Animal
{
private:
    string name;
    //int age;
    //double height;
public:
    Conservator()
    {

    }
    Conservator(string name,string n):Animal(n),name(name)
    {

    }
    void perform()
    {
        cout << "狮子的体重为200公斤,体长1,6米,是肉食性动物,比较凶残" << endl;
        cout << "大象的体重为1吨,体长2米,是饲草性动物,比较温顺" << endl;
        cout << "猴子的体重为30,身高1米,是杂食性动物" << endl;
    }
};
int main()
{
    Sun a1("小黄","大壮","小跳","刘晓颖");
    Animal *p=&a1;
    p->perform();
    Conservator a2("","");
    p=&a2;
    p->perform();
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值