#include
using namespace std;
class Animal
{
public:
Animal(const char*name=“animal”)
{
m_name=name;
}
virtual void show()const
{
cout<<“animal is display”<<endl;
}
private:
string m_name;
};
class Lion :public Animal
{
public:
Lion(const char* name=“Animal”)
:m_strName(name)
{}
void show()const
{
cout<<"liono is display"<<endl;
}
private:
string m_strName;
};
class Elephant :public Animal
{
public:
Elephant(const char* name=“Animal”)
:m_strName(name)
{}
void show()const
{
cout<<"Elephant is display"<<endl;
}
private:
string m_strName;
};
class Dolphin :public Animal
{
public:
Dolphin(const char* name=“Animal”)
:m_strName(name)
{}
void show()const
{
cout<<"Dolphin is display"<<endl;
}
private:
string m_strName;
};
class trainer
{
public:
struct Node //类
{
Node(Animal *data=NULL)//构造函数
{
animal=data; //node 有两个成员
//数据 和指针
next=NULL;
}
void show()const
{
animal->show();
}
Animal *animal;
struct Node* next;
};
trainer()
{
m_frist=NULL;
m_ilen=0;
}
void insert(Animal* animal)
{
Node *node= new Node(animal);
node->next=m_frist;
m_frist=node;
m_ilen++;
}
void remove(Animal* animal)
{
if(m_ilen<1)
{
cout<<"驯兽元没有动物"<<endl;
}
else
{
Node *node=m_frist;
Node *cur;
while(node)
{ cur=node;
if(node->animal==animal)
{
}
}
}
}
void show()const
{int x=m_ilen;
Node * node=m_frist;
while(node)
{ cout<<"第"<<x<<"个动物在表演"<<endl;
node->show();
node=node->next;
x--;
}
}
private:
Node* m_frist;
int m_ilen;
};
int main(void)
{
trainer t;
t.insert(new Lion(“lion”));//产生一个对象
// t.show();
t.insert(new Elephant(“lion”));//产生一个对象
t.insert(new Dolphin("lino "));//产生一个对象
t.insert(new Lion(“lion”));//产生一个对象
t.insert(new Dolphin(“lion”));//产生一个对象
t.insert(new Elephant(“lion”));//产生一个对象
t.show();
return 0;
}