Abstract Base Class C Program Create an abstract base class

Abstract Base Class (C++ Program)

Create an abstract base class called Animal which has the following pure virtual member functions: talk( ), move( ) and the following attribute: animalType (which is a pointer to a dynamically allocated string.)

Then create the following derived classes (from the animal class): reptile, bird, and mammal.


Here are the concrete classes:
From the reptile class derive lizard and snake.
From bird derive eagle and chicken.
From mammal derive bear, hyena and lion.


Each concrete class needs to override the talk() and move() functions. Also each concrete class will have the operator<<( ) defined. The output of cout << smokey; (assuming smokey is a bear) will be the animalType , the sound he makes (talk( ) ) and how he moves ( move( )). Here is an example:


int main()
{
bear smokey; // using the concrete class
cout << smokey // prints out: bear, growl, walk
animal *aptr = new bear; // I could have used an animal pointer
cout << *aptr; // prints the same results: bear, growl, walk
return 0;
}


Create an array of animal pointers called zoo. Make it 10 in size. Here is what the menu should look like:
----Zoo Cages----
1 [empty]
2 [empty]
3 [empty]
4 [snake]
5 [eagle]
6 [bear]
7 [empty]
8 [empty]
9 [lion]
10 [hyena]
----Menu----
1) Add
2) Remove
3) Display all animals
4) Display animal count
5) Exit


If the user selects 1) then ask for a cage number and the animal he wishes to put in that cage. Be sure to check the cage for an existing animal first. The user cannot put an animal in a cage that is already occupied.

If the user selects 2) then ask for the cage number and remove the animal from that cage (use the destructor). If there is no animal in the cage, issue an error to the user.

If the user selects 3) then display the contents of each cage. The display function will show each cage number as well as the animalType of the animal, the sound it makes and how it moves, in other words, use the operator<<( ). All this information must be on a single screen. The output screen is up to you.

If the user selects 4) then display the count of the number of animals in your zoo. In the above example, you will have 5. You should use a static data member in the animal class to keep track of the number of animals. You should increase that count each time the animal constructor is called and decrease the count when the animal destructor is called.

***Use Virtual Functions and the animal base class MUST be abstract

Solution

public class maxCalc2 {
public static void main (String[] args) {
float[] A = new float[10];
int n = 0;
   System.out.println(\"Enter a few numbers, ended by 0: \");
   A[0] = Keyboard.readFloat();
   while (A[n] != 0) {
n = n + 1;
A[n] = Keyboard.readFloat();
}
System.out.println(\"Their maximum is \" + MAX(A, n));
}
public static float MAX (float[] A, int n) {
float result = A[0];
   for (int i=0; i<n; i++)
if (A[i] > result)
result = A[i];
   return result;
}
}

T

Abstract Base Class (C++ Program) Create an abstract base class called Animal which has the following pure virtual member functions: talk( ), move( ) and the fo
Abstract Base Class (C++ Program) Create an abstract base class called Animal which has the following pure virtual member functions: talk( ), move( ) and the fo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site