10.12c++作业

#include 

using namespace std;

class Zoo
{
public:
    string name;
public:
    Zoo(){}
    Zoo(string name):name(name)
    {}
    virtual void perform()
    {
        cout << "不知道说点啥,简单讲两句,,,,," << endl;
    }
};
class Dinosaurs :public Zoo//恐龙
{
private:
    string talent; //才艺
public:
    Dinosaurs(){}
    Dinosaurs(string name,string talent):Zoo(name),talent(talent)
    {}
    void perform()
    {
        cout << name << ":" << "踩单车" << endl;
    }
};

class Fish :public Zoo//鱼
{
private:
    string talent;
public:
    Fish(){}
    Fish(string name, string talent):Zoo(name),talent(talent)
    {}
    void perform()
    {
        cout << name << ":" << "开挖掘机" << endl;
    }
};

class Tiger :public Zoo //老虎
{
private:
    string talent;
public:
    Tiger(){}
    Tiger(string name,string talent):Zoo(name),talent(talent)
    {}
    void perform()
    {
        cout << name << ": 点火!!!" << endl;
    }
};

int main()
{
    Dinosaurs d("大王龙","自行车");
    Fish f("秋刀鱼","开挖掘机");
    Tiger t("三角函数","玩打火机");
    Zoo *p;
    p=&d;
    p->perform();
    p=&f;
    p->perform();
    p=&t;
    p->perform();

    return 0;
}

你可能感兴趣的:(c++,算法,开发语言)