Question
Suppose we have a class hierarchy of animals where the classes are Animal, Cat, TabbyCat, Dog and Chihuahua. All the classes have or inherit the
Suppose we have a class hierarchy of animals where the classes are Animal, Cat, TabbyCat, Dog and Chihuahua.
All the classes have or inherit the function makeSound() which will output a sound to the console.
Animals never make any sound so makeSound() will be a pure virtual function in the Animal class. Cat and Dog are derived from Animal and override makeSound().
TabbyCat is derived from Cat and inherits makeSound(). Chihuahua is derived from Dog and overrides makeSound()with code that calls the makeSound() from Dog then outputs Yap Yap.
a. Write the prototype for the Animal::makeSound() function.
b. Write the implementation for the Chihuahua::makeSound() function.
c. Illustrate dynamic binding by making an array of Animalpointers of size 4 and pointing its elements to objects of each type of Animal (Dog, Cat, TabbyCat, Chihuahua).
Then loop through the array and call makeSound() for each element.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started