⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animals.cpp

📁 通过类型姓名年龄类别来显示动物
💻 CPP
字号:



#include"Animals.h"

//****************************************************
//*	file Animals.cpp  Implementations of class Animal*
//****************************************************

int Animal::mCounter = 0;


Animal::Animal()                         // Default constructor 
{
	  mAnimalTypeID = GENERIC_ANIMAL_ID; // Animal type ID
	  mName[0] = 0;                      // Set the name to zero
	  mUniqueNumber = mCounter++;		 // Animal unique number
      mKindOfAnimal = CANINES;           // Set the type to Canines
	  mAge = 0;                          // Asign  zero to the Age 
	  mSex = 'M';				         // Asign Male to Sex
	  mCage = 0;                         // Asign zero to cage
	  mNext = NULL;                      // Asign NULL to next
}   

Animal::Animal( char * Name, AnimalKindType type, int Age, char Sex, int Cage )

{     //constructor function
	  SetName ( Name );                  // To Set the Name
	  mUniqueNumber = mCounter++;		 // Animal unique number
      mKindOfAnimal = type;	             // Animal type
	  mAge = Age;                        // Animal Age
	  mSex = Sex;				         // Animal Sex (F/M)
	  mCage = Cage;                      // Animal cage number
	  mAnimalTypeID = GENERIC_ANIMAL_ID; // Animal ID
	  mNext = NULL;                      // Asign NULL to next
}
            
Animal::~Animal()                        // Destructor
{
}       

char * Animal::AnimalTypeString()

{
	switch ( mKindOfAnimal )            // Switch statement

	{
		case CANINES:                   // If the animal is Canine
			return "CANINES";           // Return Canine

		case FELINES:                   // If the animal is Filine
			return "FELINES";           // Return Filine

		case RAPTILES:
			return "RAPTILES"; 

		case BIRDS:
			return "BIRDS";

		default:                        // If not Canine not Filine
			return "N/A";               // Return Not Available
	}
}

void Animal::Display( void )       // the output of the info of an animal

{

	cout<<"\tNumber:"<<mUniqueNumber;
	cout<<"\tName  :"<<mName;
	cout<<"\tType  :"<<AnimalTypeString();
	cout<<"\tSex   :"<<mSex;
	cout<<"\tAge   :"<<mAge;
	cout<<"\tCage  :"<<mCage<<endl;
	//cout<<endl;
}


void Animal::GetAnimalInfo()

{
	cout<<"Name.......: ";         // Get the Animal name from the user               
	cin>> mName;
	cin.get();
	do
	{

 	   cout<<"Sex (M/F)..: ";      // Get the Animal Sex from the user
	   cin>> mSex;
	   }while ( mSex != 'M' && mSex != 'F' );
	cin.get();
	cout<<"Age........: ";         // Get Age from the user 
	cin>> mAge;
	cin.get();
	cout<<"Cage.......: ";         // Get Cage from the user
	cin>> mCage;
	cin.get();
}


//************************************************************************

//***********************************
//*	Implementations of class Wolve  *
//***********************************

Wolve::Wolve()                        // Default constructor
{
	SetAnimalTypeID ( WOLVE_ID );     // Wolve ID
	SetAnimalType( CANINES );         // Wolve is Canine
}

Wolve::Wolve( char * Name, int Age, char Sex, int Cage ):
	      Animal( Name, CANINES, Age, Sex, Cage )

{
     
	SetAnimalTypeID ( WOLVE_ID );
}

Wolve::~Wolve()                       // Destructor
{
}

void Wolve::Display ( void )          // Display info func

{
	cout <<"Wolve";                 // Display Wolve
	Animal::Display();                // Call Display function
}

void Wolve::GetAnimalInfo()

{
	cout<<"\nEnter information for a new wolve:\n";
   	Animal::GetAnimalInfo();          // call the Animal information function
}


//***********************************************************************



//*********************************
//*	Implementations of class Bear *
//*********************************

Bear::Bear()                          // Default constructor

{
	SetAnimalType( CANINES );         // Set Bear to Canine Animal
	SetAnimalTypeID(BEAR_ID	);        // Set the Bear ID
}

Bear::Bear( char * Name, char * Color, int Age, char Sex, int Cage ):
	      Animal( Name, CANINES, Age, Sex, Cage )

{   // constructo
	strcpy ( mColor, Color );         // Get the Bear color 
	SetAnimalTypeID(BEAR_ID	);        // Call Animal ID function
}

Bear::~Bear()                         // Destructor
{
}

void Bear::Display ( void )

{

	cout <<"Bear\tColor :"<<mColor;  // Get the Bear color 
	Animal::Display();                       // Call display function
}

void Bear::GetAnimalInfo()

{
	cout<<"\nEnter information for a new bear:\n";
	cout <<"Color......: ";
	cin>> mColor;                         // Input of the color
	Animal::GetAnimalInfo();              // call Animal infor function
}


//************************************************************************

//*********************************
//*	Implementations of class Lion *
//*********************************

Lion::Lion()                            // Default constructor

{
	SetAnimalType( FELINES );           // Lion is Filine
	SetAnimalTypeID(LION_ID	);          // Lion identification
}

Lion::Lion( char * Name, int Pride, int Age, char Sex, int Cage ):
	      Animal( Name, FELINES, Age, Sex, Cage )

{
	mPride = Pride;                     // Lion Pride
	SetAnimalTypeID(LION_ID	);          // Call Lion type ID function
}

Lion::~Lion()                           // Destructor
{
}

void Lion::Display ( void )

{
	cout <<"Lion\tPride :"<<mPride;// Lion Pride
	Animal::Display();                       // Call Animal Display function
}

void Lion::GetAnimalInfo()

{
	cout<<"\nEnter information for a new lion:\n";
	cout<<"Pride......: ";                // Get the Pride from the user
	cin>> mPride;
	Animal::GetAnimalInfo();              // Call Animal GetAnimalInfo function
}


//***********************************************************************

//*********************************
//*	Implementations of class Tiger*
//*********************************

Tiger::Tiger()                           // Default constructor

{
	SetAnimalType( FELINES );             // Tiger is Feline
	SetAnimalTypeID ( TIGER_ID );         // Tiger identification
}


Tiger::Tiger(char * Name, double Protein, int Age, char Sex, int Cage ):
	      Animal( Name, FELINES, Age, Sex, Cage )

{
	mProtein = Protein;                   // Tiger s protein
	SetAnimalTypeID ( TIGER_ID );         // Call AnimalTypeID func for Tiger
}


Tiger::~Tiger()                                  // Destructor
{
}


void Tiger::Display ( void )

{
	cout <<"Tiger\tProtein:"<<mProtein; // Display Tiger protein
	Animal::Display();                           // Call Animal display function
}


void Tiger::GetAnimalInfo()

{
	cout<<"\nEnter information for a new tiger:\n";
	cout <<"Protein....: ";               // Get the Tiger Protein from user
	cin>> mProtein;
	Animal::GetAnimalInfo();             // Call Animal GetAnimalInfo function 
}


//************************************************************************

//***********************************
//*	Implementations of class Coyotes*
//***********************************

Coyote::Coyote()                        // Default constructor

{
	SetAnimalTypeID ( COYOTE_ID );      // Coyote ID
	SetAnimalType( CANINES );           // Coyote is Canine
}

Coyote::Coyote( char * Name, int Age, char Sex, int Cage ):
	      Animal( Name, CANINES, Age, Sex, Cage )

{
     
	SetAnimalTypeID ( COYOTE_ID );
}

Coyote::~Coyote()                       // Destructor
{
}

void Coyote::Display ( void )          // Display info func

{
	cout <<"Coyote\n";                 // Display Coyote
	Animal::Display();                 // Call Display function
}

void Coyote::GetAnimalInfo()

{
	cout<<"\nEnter information for a new Coyote:\n";
   	Animal::GetAnimalInfo();          // call the Animal information function
}
//***********************************************************************



//***********************************
//*	Implementations of class WildCat*
//***********************************

WildCat::WildCat()                           // Default constructor

{
	SetAnimalType( FELINES );               // WildCat is Feline
	SetAnimalTypeID ( WILDCAT_ID );         // WildCat identification
}


WildCat::WildCat(char * Name, double Protein, int Age, char Sex, int Cage ):
	      Animal( Name, FELINES, Age, Sex, Cage )

{
	mProtein = Protein;                   // WildCat s protein
	SetAnimalTypeID ( WILDCAT_ID );       // Call AnimalTypeID func for WildCat
}


WildCat::~WildCat()                                  // Destructor
{
}


void WildCat::Display ( void )

{
	cout <<"WildCat\tProtein:"<<mProtein; // Display WildCat protein
	Animal::Display();                           // Call Animal display function
}


void WildCat::GetAnimalInfo()

{
	cout<<"\nEnter information for a new WildCat:\n";
	cout <<"Protein....: ";               // Get the WildCat Protein from user
	cin>> mProtein;
	Animal::GetAnimalInfo();             // Call Animal GetAnimalInfo function 
}
//*************************************************************************


//*************************************
//*	Implementations of class Leopard  *
//*************************************

Leopard::Leopard()                           // Default constructor

{
	SetAnimalType( FELINES );               // Leopard is Feline
	SetAnimalTypeID ( LEOPARD_ID );         // Leopard identification
}


Leopard::Leopard(char * Name, double Protein, int Age, char Sex, int Cage ):
	      Animal( Name, FELINES, Age, Sex, Cage )

{
	mProtein = Protein;                   // Leopard s protein
	SetAnimalTypeID ( LEOPARD_ID );       // Call AnimalTypeID func for Leopard
}


Leopard::~Leopard()                                  // Destructor
{
}


void Leopard::Display ( void )

{
	cout <<"Leopard\tProtein:"<<mProtein; // Display Leopard protein
	Animal::Display();                           // Call Animal display function
}


void Leopard::GetAnimalInfo()

{
	cout<<"\nEnter information for a new Leopard:\n";
	cout <<"Protein....: ";               // Get the Leopard Protein from user
	cin>> mProtein;
	Animal::GetAnimalInfo();             // Call Animal GetAnimalInfo function 
}

//************************************************************************

//***********************************
//*	Implementations of class Fox    *
//***********************************

Fox::Fox()                            // Default constructor

{
	SetAnimalTypeID ( FOX_ID );       // Fox ID
	SetAnimalType( CANINES );         // Fox is Canine
}

Fox::Fox( char * Name, int Age, char Sex, int Cage ):
	      Animal( Name, CANINES, Age, Sex, Cage )

{
     
	SetAnimalTypeID ( FOX_ID );
}

Fox::~Fox()                             // Destructor
{
}

void Fox::Display ( void )            // Display info func

{
	cout <<"Fox\n";                   // Display Fox
	Animal::Display();                // Call Display function
}

void Fox::GetAnimalInfo()

{
	cout<<"\nEnter information for a new Fox\n";
   	Animal::GetAnimalInfo();      // call the Animal information function
}


//***********************************************************************


//*************************************
//*	Implementations of class WildDogs *
//*************************************

Dogs::Dogs()                          // Default constructor

{
	SetAnimalType( CANINES );         // Set Dogs to Canine Animal
	SetAnimalTypeID(DOGS_ID	);        // Set the Dogs ID
}

Dogs::Dogs( char * Name, char * Color, int Age, char Sex, int Cage ):
	      Animal( Name, CANINES, Age, Sex, Cage )

{   
    // constructor
	strcpy ( mColor, Color );         // Get the Dogs color 
	SetAnimalTypeID(DOGS_ID	);        // Call Animal ID function
}

Dogs::~Dogs()                         // Destructor
{
}

void Dogs::Display ( void )

{
	cout <<"Dogs\tColor :"<<mColor;// Get the Dogs color 
	Animal::Display();                       // Call display function
}

void Dogs::GetAnimalInfo()

{
	cout<<"\nEnter information for a new Dog:\n";
	cout <<"Color......: ";
	cin>> mColor;                         // Input of the color
	Animal::GetAnimalInfo();              // call Animal infor function
}


//***********************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -