再读C++ Primer 写了个小例子——练习多态虚函数的特性(08-01-25)
2008-03-19 22:08
489 查看
再读C++ Primer 写了个小例子——练习多态虚函数的特性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//操作
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Animal(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(int i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual ~Animal(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual void ShowMe() = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getAnimalType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int animalType;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Animal::Animal(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//Animal::Animal(int i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// animalType = i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Animal::~Animal(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Animal::getAnimalType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return animalType;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Cat :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~Cat(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat(char* ctype,int w,char* cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void operator <<(Cat & cat);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getWeight();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getFood();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char type[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char food[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".at.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Cat::Cat(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(type,0,sizeof(type));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(food,0,sizeof(food));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Cat::~Cat(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Cat::Cat(char* ctype,int w,char* cfood)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(atype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(type,ctype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(food,cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = w;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat::animalType=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void Cat::ShowMe()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"The Cat' properties"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Type: "<<getType()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Weight: "<<getWeight()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Food: "<<getFood()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Cat::getType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Cat::getWeight()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Cat::getFood()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "iostream"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//istream & operator>>(istream& is,Dog& dog)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// cout<<"is"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// is>>dog.type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// is>>dog.food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// is>>dog.weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// return is;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Dog :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//操作
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~Dog(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog(char* ctype,int w,char* cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// friend istream& operator>>(istream& is,Dog& dog);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getWeight();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getFood();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char type[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char food[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".dog.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dog::Dog(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(type,0,sizeof(type));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(food,0,sizeof(food));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dog::~Dog(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dog::Dog(char* ctype,int w,char* cfood)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(type,ctype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(food,cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = w;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog::animalType=2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void Dog::ShowMe()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"The Dog' properties"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Type: "<<getType()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Weight: "<<getWeight()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Food: "<<getFood()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Dog::getType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Dog::getWeight()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Dog::getFood()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#define MAX 12
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class shelves
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shelves(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~shelves(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void addElement(Animal* animal);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void deleteElement(int index);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void searchType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void getTypeTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Animal* element[MAX];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int total;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// int typeTotal;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".shelves.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
shelves::shelves(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[i]=NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
total=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// typeTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
shelves::~shelves(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// delete element[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[i]=NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::addElement(Animal* animal)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(total<MAX)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[total] = animal;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
total++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::deleteElement(int index)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(index >= 0 && index < MAX)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[index] = NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
total--;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::searchType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[i]->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int shelves::getTotal()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return total;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::getTypeTotal()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int catTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int dogTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int snakeTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(element[i]->getAnimalType() == 1)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
catTotal ++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if(element[i]->getAnimalType() == 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dogTotal ++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
snakeTotal ++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// return typeTotal;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Cat total: "<<catTotal<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Dog Total: "<<dogTotal<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Snake Total: "<<snakeTotal<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Snake :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~Snake(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake(char* ctype,int w,char* cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getWeight();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getFood();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char type[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char food[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".snake.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Snake::Snake(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(type,0,sizeof(type));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(food,0,sizeof(food));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Snake::~Snake(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Snake::Snake(char* ctype,int w,char* cfood)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(type,ctype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(food,cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = w;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake::animalType=3;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void Snake::ShowMe()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"The Snake' properties"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Type: "<<getType()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Weight: "<<getWeight()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Food: "<<getFood()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Snake::getType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Snake::getWeight()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Snake::getFood()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// test0825.cpp : Defines the entry point for the console application.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "stdafx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "iostream"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "at.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Dog.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Snake.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "shelves.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int _tmain(int argc, _TCHAR* argv[])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shelves shel;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat* cat;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog* dog;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//Dog* dog1=new Dog();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//cin>>dog1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake* snake;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* name= new char[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* food=new char[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"请输入3个动物的类型,动物喜欢的食物,动物的重量"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i = 0;i<3;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cin>>name>>food>>weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cat=new Cat(name,weight,food);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.addElement(cat);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==1)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dog=new Dog(name,weight,food);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.addElement(dog);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
snake= new Snake(name,weight,food);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.addElement(snake);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cat->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dog->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
snake->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"显示笼子的动物数量: "<<shel.getTotal()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"显示笼子的动物类型: ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.searchType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"显示笼子的动物类型数量: ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.getTypeTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//void addElement(Animal* animal);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void deleteElement(int index);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void searchType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// int getTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void getTypeTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// cat.ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cin>>weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete cat;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete dog;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete snake;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
name = NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
food = NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//操作
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Animal(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(int i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual ~Animal(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual void ShowMe() = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getAnimalType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int animalType;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Animal::Animal(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//Animal::Animal(int i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// animalType = i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Animal::~Animal(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Animal::getAnimalType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return animalType;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Cat :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~Cat(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat(char* ctype,int w,char* cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void operator <<(Cat & cat);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getWeight();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getFood();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char type[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char food[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".at.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Cat::Cat(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(type,0,sizeof(type));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(food,0,sizeof(food));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Cat::~Cat(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Cat::Cat(char* ctype,int w,char* cfood)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(atype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(type,ctype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(food,cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = w;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat::animalType=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void Cat::ShowMe()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"The Cat' properties"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Type: "<<getType()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Weight: "<<getWeight()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Food: "<<getFood()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Cat::getType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Cat::getWeight()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Cat::getFood()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "iostream"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//istream & operator>>(istream& is,Dog& dog)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// cout<<"is"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// is>>dog.type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// is>>dog.food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// is>>dog.weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// return is;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Dog :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//操作
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~Dog(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog(char* ctype,int w,char* cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// friend istream& operator>>(istream& is,Dog& dog);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getWeight();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getFood();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char type[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char food[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".dog.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dog::Dog(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(type,0,sizeof(type));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(food,0,sizeof(food));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dog::~Dog(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dog::Dog(char* ctype,int w,char* cfood)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(type,ctype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(food,cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = w;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog::animalType=2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void Dog::ShowMe()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"The Dog' properties"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Type: "<<getType()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Weight: "<<getWeight()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Food: "<<getFood()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Dog::getType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Dog::getWeight()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Dog::getFood()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#define MAX 12
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class shelves
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shelves(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~shelves(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void addElement(Animal* animal);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void deleteElement(int index);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void searchType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void getTypeTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Animal* element[MAX];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int total;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// int typeTotal;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".shelves.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
shelves::shelves(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[i]=NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
total=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// typeTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
shelves::~shelves(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// delete element[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[i]=NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::addElement(Animal* animal)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(total<MAX)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[total] = animal;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
total++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::deleteElement(int index)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(index >= 0 && index < MAX)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[index] = NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
total--;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::searchType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
element[i]->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int shelves::getTotal()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return total;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void shelves::getTypeTotal()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int catTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int dogTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int snakeTotal=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<MAX;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(element[i]->getAnimalType() == 1)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
catTotal ++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if(element[i]->getAnimalType() == 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dogTotal ++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
snakeTotal ++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// return typeTotal;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Cat total: "<<catTotal<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Dog Total: "<<dogTotal<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Snake Total: "<<snakeTotal<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#pragma once
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class Snake :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public Animal
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~Snake(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake(char* ctype,int w,char* cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int getWeight();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* getFood();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char type[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char food[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "StdAfx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include ".snake.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Snake::Snake(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(type,0,sizeof(type));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
memcpy(food,0,sizeof(food));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Snake::~Snake(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Snake::Snake(char* ctype,int w,char* cfood)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Animal(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(type,ctype);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strcpy(food,cfood);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
weight = w;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake::animalType=3;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void Snake::ShowMe()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"The Snake' properties"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Type: "<<getType()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Weight: "<<getWeight()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"Food: "<<getFood()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Snake::getType()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return type;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int Snake::getWeight()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char* Snake::getFood()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// test0825.cpp : Defines the entry point for the console application.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "stdafx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "iostream"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Animal.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "at.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Dog.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "Snake.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "shelves.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int _tmain(int argc, _TCHAR* argv[])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shelves shel;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cat* cat;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dog* dog;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//Dog* dog1=new Dog();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//cin>>dog1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Snake* snake;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* name= new char[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char* food=new char[20];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int weight = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"请输入3个动物的类型,动物喜欢的食物,动物的重量"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i = 0;i<3;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cin>>name>>food>>weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cat=new Cat(name,weight,food);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.addElement(cat);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==1)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dog=new Dog(name,weight,food);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.addElement(dog);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
snake= new Snake(name,weight,food);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.addElement(snake);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cat->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dog->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
snake->ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"显示笼子的动物数量: "<<shel.getTotal()<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"显示笼子的动物类型: ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.searchType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"显示笼子的动物类型数量: ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
shel.getTypeTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//void addElement(Animal* animal);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void deleteElement(int index);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void searchType();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// int getTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// void getTypeTotal();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// cat.ShowMe();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cin>>weight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete food;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete cat;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete dog;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete snake;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
name = NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
food = NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- 再读C++ Primer 写了个小例子(08-01-16)
- 再读C++ Primer 写了个小例子——运算符重载(08-01-17)
- 再读C++ Primer 写了个小例子——模板的操作(08-01-18)
- 再读C++ Primer 写了个小例子——实现stack类的压栈弹栈功能(08-12-10)
- 再读C++ Primer 写了个小例子——实现Vector类的自动添加元素功能(08-12-10)
- 《C++ Primer》读书笔记-第六章 01 函数基础
- 25-GUI-08-GUI(练习-列出目录内容)
- 001-练习01:linux_命令使用40道例子
- OC基础--多态 及 三特性小练习
- 再读C++ Primer 写了些小例子来熟悉C++基本语法
- 算法练习——C++CH 08 01
- 《C++ Primer》第五版课后习题解答_第二章(1)(01-08)
- 再读C++ Primer 写了个小例子——友员类的操作
- php部分--面向对象三大特性-封装(另加连续调用的一个例子)、继承(重写、重载的例子)、多态;
- 15-08-02 例子:下拉菜单(阻止事件冒泡函数)
- 数据结构练习 01-复杂度2. Maximum Subsequence Sum (25)
- 用例子来理解c++的类,构造函数,类的多态,成员函数,成员变量
- C++中多态特性深入探究---虚函数
- 一个例子帮你搞懂C#语言高级特性系列(01) --- 运算符重载
- linux下练习 c++ 函数模版例子