611作业

cpp 复制代码
#include <iostream>

using namespace std;
class Animal
{
private:
    string name;
    string program;
public:
    Animal(){}
    Animal(string name="am",string program="pg"):name(name),program(program){}

    virtual void perfrom()
    {
        cout << name << " " << program << endl;
    }
};
class Hum
{
public:
    virtual void introduce()
    {
        cout << "Human introduce" << endl;
    }

};
class Lion:public Animal,public Hum
{
public:
    Lion(string name = "lion",string program = "eat"):Animal(name,program){}
    virtual void perfrom()
    {
        Animal::perfrom();
    }
    virtual void introduce()
    {
        Hum::introduce();
    }
};
class Elephant:public Animal,public Hum
{
public:
    Elephant(string name = "elephant",string program = "run"):Animal(name,program){}
    virtual void perfrom()
    {
        Animal::perfrom();
    }
    virtual void introduce()
    {
        Hum::introduce();
    }
};
class Monkey:public Animal,public Hum
{
public:
    Monkey(string name = "monkey",string program = "jump"):Animal(name,program){}
    virtual void perfrom()
    {
        Animal::perfrom();
    }
    virtual void introduce()
    {
        Hum::introduce();
    }
};

int main()
{
    Lion l1;
    Animal *p=&l1;
    Hum *q=&l1;
    p->perfrom();
    q->introduce();

    Elephant e2;
    Animal *p2=&e2;
    Hum *q2=&e2;
    p2->perfrom();
    q2->introduce();

    Monkey m3;
    Animal *p3=&m3;
    Hum *q3=&m3;
    p3->perfrom();
    q3->introduce();

    return 0;
}
相关推荐
clint4569 小时前
C++进阶(1)——前景提要
c++
夜悊13 小时前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴14 小时前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0011 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾1 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
один but you1 天前
constexpr函数
c++
凡人叶枫1 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫1 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++
小胖xiaopangss1 天前
BRpc使用
c++·rpc
-森屿安年-1 天前
63. 不同路径 II
c++·算法·动态规划