(E) ZooΒΆ
Goal: I will learn to inherit a simple class from an existing base class and to add functionality to the inherited class.
Instructions:
Retrieve the code template: template/12/zoo/
-> student/12/zoo/
.
Study first the ready-made classes and the main program that creates different objects and calls methods for those objects.
Your task is to implement by inheriting the new classes
Mammal
, Giraffe
, and Cockatoo
such that:
Mammal
is capable to perform all the actions asAnimal
, and its moving sounds as"Kip kop kip kop"
. In addition, it has the methodsuckle(std::ostream& output)
that prints"Mus mus"
.Giraffe
is capable to perform all the actions asMammal
, and in addition, it has the methodmake_noise(std::ostream& output)
that prints"Ori ori ori!"
.Cockatoo
is capable to perform all the actions asBird
, and it has the methodsing(std::ostream& output)
that prints"Kee-ow kee-ow!"
.
The above text is clarified in the figure below. The figure shows the public methods and private member variables of each class. For clarity sake, the parameters and return values of the methods have been omitted.
The ready-made main program has examples (commented away) on how to use the classes to be implemented. You can edit the main program and write more precise tests in it. The automated tests do not test the main function, but only the classes that you will implement.
Tips for completing the assignment:
- Based on the previous material section, you should understand how inheritance works. In such case, you should see that this task requires only a few lines of code. Therefore, you need not copy existing code in no place.
A+ presents the exercise submission form here.