作业

#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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值