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

📄 zoomain.cpp

📁 通过类型姓名年龄类别来显示动物
💻 CPP
📖 第 1 页 / 共 2 页
字号:


//***********************
//*	File: ZooMain.cpp   *
//***********************

#include <iostream.h>
#include "Zoo.h"
#include "Menu.h"

Zoo MyZoo;

// declaire char as static for the count
static char * AddAnimalMenuStr[] = {  "Bear",
                                      "Tiger",
									  "Lion", 
									  "Wolve", 
									  "Coyote",
                                      "WildCat",
                                      "Leopard",
									  "Fox", 
									  "Dogs"};

void Warning ( char * text = NULL )

{
	if ( text != NULL )
	    cout<<"\t\t"<<text<<endl;        // Prints a message to the user
	EatKeys();
  	cout<<"\t\tPress ENTER To Continue..."<<endl;
	while ( cin.get() != '\n' );
}

void AddAnimals( void )         // Add Animal function

{
	int choice;                 // user choices
	Animal *pAnim;              // Pointer to Animal
    // Add Animal to Zoo Title
	Menu AnimalMenu ( "\n\n\t\tAdd Animal To The Research Zoo", AddAnimalMenuStr, 9);
    // to loop for the user so he/she can add as much Animals they wish
	for (;;)

	{
		choice = AnimalMenu.MakeChoice(); // Make a choice function

		switch ( choice )                 // Switch statement for adding
		{

		case -1:                          // For Animal not existing
			return;

		case 0:
			pAnim = new Bear;             // To Add a Bear
			break;

		case 1:
			pAnim = new Tiger;            // To Add a Tiger
			break;

		case 2:
			pAnim = new Lion;             // To Add a Lion
			break;

		case 3:
			pAnim = new Wolve;            // To Add a Wolve
			break;

        case 4:
			pAnim = new Coyote;          // to Add a Coyote
			break;

		case 5:
			pAnim = new WildCat;         // To Add WildCat
			break;

		case 6:
			pAnim = new Leopard;        // To Add Leopard
			break;

		case 7:
			pAnim = new Fox;            // To Add Fox
			break;

		case 8:
			pAnim = new Dogs;          // To Add Dog
			break;

		}

		pAnim->GetAnimalInfo();           // Pointer to GetAnimalInf function
		// If the Animal is not existing
		if ( MyZoo.AddAnimal ( pAnim ) == FALSE )

		{
			delete pAnim;
			// Give warning to the user
			Warning ( "ERROR Adding Animal To Zoo !" );
		}

		else

		{
			// Display the total of the Animal
			cout<<"Total Number Of Animals In The Zoo :"<<MyZoo.CountAnimals(GENERIC_ANIMAL_ID)<<endl;
			Warning ( );
		}
	}
}

void DeleteAnimals()               // Function for deleting an Animal

{
	int choice, Number;
	// Display the delete Menu_Animal
	Menu AnimalMenu ( "\n\n\t\tRemove Animals From Research Zoo", AddAnimalMenuStr, 9);

	for(;;)  // To loop for more delete if the user wishes to do so..

	{
		// if the user choise is in the menu delete (-1) Animal
		choice = AnimalMenu.MakeChoice();
		if ( choice == -1 ) return;
		if ( MyZoo.CountAnimals( choice+1 ) == 0 ) // no animals to delete

		{
			// if the amount of deletion is more than what's in the zoo container
			// Give warnimg that there is no more from that type to delete.
			cout<<"\nThere Are No "<<AddAnimalMenuStr[choice]<<" To Be Deleted !\n";
		}

		else

		{
			clrscr();
			cout<<"\t\t\tDeleting "<<AddAnimalMenuStr[choice]<<".\n\n";
			MyZoo.Display ( choice+1 );
			// to delete an animal via the unique number 
			cout<<"Enter Animal Number To Delete :";
			cin>>Number;
			// If the ID number the user enter is not correct
			if ( NULL == MyZoo.RemoveAnimalViaNumber( Number, TRUE ) )
				cout << "Can Not Delete Animal :"<<Number<<endl;
             // If the ID number the user enter is correct
			else cout <<"Animal <"<<Number<<"> Was Deleted.\n";
		}

		Warning ( );
	}

}

void DisplayAnimalsByType( void )

{
	int choice;  
	// To display the menu of all Animals, or to diplay each type of Animal
    static char * DispAnimalMenuStr[] = {"All Animals",
		                                 "Bears",
										 "Tigers",
										 "Lions", 
										 "Wolves", 
										 "Coyote", 
										 "WildCat",   
										 "Leopard",
										 "Fox", 
										 "Dogs"};
    // Display Animal Menu
	Menu AnimalMenu ( "\n\n\t\tDisplay Animals In The Research Zoo\n\n", DispAnimalMenuStr, 10);

	for (;;)   // For loop!! the user can choose as much as he/she wishes

	{
		choice = AnimalMenu.MakeChoice(); // Get the choice
		if ( choice == -1 ) return;
		clrscr();                         // Clear screen function
		cout << "\tData of " << DispAnimalMenuStr[choice] << " In The Zoo.\n\n";
		MyZoo.Display ( choice );         // Display choice
	}
}

void DisplayAnimalsByCage( void )

{
	int cage;
    // The user to enter the cage number to browse the Animal is such cage..
	cout<<"\nEnter The Cage Number You Want To Browse :";
	cin>>cage;                        // Input for the cage number
	clrscr();                         // Clear screen function
    // Display the list
	cout<<"\t\tData Of Animals In Cage <"<<cage<<">\n\n";
	// Display the Animals via the cage requested
	MyZoo.DisplayViaCage( cage );
}

void IncrementAge( )

{
	int cage, number;
	Animal * anim;

	if ( MyZoo.CountAnimals() == 0 )  // give warning if the Zoo is empty

	{
		Warning ( "Nothing To Increment !" );
		return;
	}

	// Input of the cage number so the user can increment the Animal Age
	cout<<"\nEnter The Cage Number\nFrom What You Want To Increment age :";
	cin>>cage;                        // Input of the cage number from user
	clrscr();                         // Clear screen function
	cout<<"\t\tData Of Animals In Cage <"<<cage<<">\n\n";
	MyZoo.DisplayViaCage( cage ); // Display the Animal(s) requested
	// the input of the unique number to increment Age
	cout<<"Enter Animal's Number Which Age To Be Incremented :";
	cin>>number;                  // Input of the unique number from user
	anim = MyZoo.FindAnimalViaNumber ( number);
	if ( anim == NULL )           // give warning if the number is not existing

	{
		// Display a message
		Warning ( "There Is	No Such Animal Number !"); 
		return;
	}

	clrscr();                             // Clear screen
	cout<<"\t\tIncrementing The Animal Age \n\n";// Increment the Age
	anim->Display();	                  // displaying current info
	Warning();                            // Call warning func
	anim->BirthDay();                     // anim point to BirthDay func
	clrscr();                             // Call clear screen function
	cout<<"\t\tAnimal Age Was Incremented !\n\n";// Display a message
	anim->Display();                      // Display current info
	Warning();                            // Give warning if no Animal
}

void MoveAnimal( )             // func to move Animal from cage to cage

{
	int cage, number;
	Animal * anim;

⌨️ 快捷键说明

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