华清远见嵌入式学习——C++——作业6

作业要求:

代码:

#include <iostream>

using namespace std;

class Animal
{
public:
    virtual void perform() = 0;

};

class Lion:public Animal
{
private:
    string foods;
    string feature;
public:
    Lion(){}
    Lion(string foods,string feature):foods(foods),feature(feature)
    {}
    void perform()
    {
        cout << "狮子喜欢吃的食物是: " << foods << " " << "狮子喜欢做: " << feature << endl;
    }
};

class Monkey:public Animal
{
private:
    string foods;
    string feature;
public:
    Monkey(){}
    Monkey(string foods,string feature):foods(foods),feature(feature)
    {}
    void perform()
    {
        cout << "猴子喜欢吃的食物是: " << foods << " " << "猴子喜欢做: " << feature << endl;
    }
};

int main()
{
    Lion l("斑马","喵喵喵的叫");
    Monkey m("香蕉","抢人类食物");
    Animal *interpreter;

    interpreter = &l;
    interpreter->perform();

    interpreter = &m;
    interpreter->perform();
    return 0;
}

代码运行效果图:

思维导图:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值