#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;
}
611作业
最新推荐文章于 2024-09-07 05:15:02 发布