12/05

12/05_第1张图片

#include 

using namespace std;

class Animal
{
private:
    string name;
public:
    Animal(){}
    Animal(string name):name(name)
    {}
    virtual void perform()=0;
};

class lion:public Animal
{
public:
    lion(){}
    lion(string name):Animal(name)
    {}
    void perform()
    {
        cout << "我是丛林之王狮子" << endl;
    }
};
class tiger:public Animal
{
public:
    tiger(){}
    tiger(string name):Animal(name)
    {}
    void perform()
    {
        cout << "我是凶猛的老虎" << endl;
    }
};
class panda:public Animal
{
public:
    panda(){}
    panda(string name):Animal(name)
    {}
    void perform()
    {
        cout << "我是国家一级保护动物熊猫" << endl;
    }
};
class mokeny:public Animal
{
public:
   mokeny(){}
    mokeny(string name):Animal(name)
    {}
    void perform()
    {
        cout << "你知道齐天大圣孙悟空吗,没错我就是猴子" << endl;
    }
};
int main()
{
    mokeny m("猴子");
    tiger t("老虎");
    panda p("熊猫");
    lion l("狮子");
    Animal *ptr;
    cout << "========================================" <perform();
    cout << "========================================" <perform();
    cout << "========================================" <perform();
    cout << "========================================" <perform();
    cout << "========================================" <

12/05_第2张图片

你可能感兴趣的:(算法)