(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 as Animal, and its moving sounds as "Kip kop kip kop". In addition, it has the method suckle(std::ostream& output) that prints "Mus mus".
  • Giraffe is capable to perform all the actions as Mammal, and in addition, it has the method make_noise(std::ostream& output) that prints "Ori ori ori!".
  • Cockatoo is capable to perform all the actions as Bird, and it has the method sing(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.

../../_images/perintahierarkia.png

The hierarchic structure of inheritance

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.