Question
SET-252 C Programming #2 Homework: 4 Polymorphism Step 1 Parent Class Create a CAnimal class. Add the following protected properties: m_strName, m_strType Add the following
SET-252 C Programming #2
Homework: 4 Polymorphism
Step 1 Parent Class
Create a CAnimal class.
Add the following protected properties: m_strName, m_strType
Add the following public methods: Get/Set Name, Get/Set Type, virtual MakeNoise.
Step 2 Child Classes
Create three or more child classes based on the CAnimal class (e.g. CDog, CCow, CDragon).
Each child class must re-define the MakeNoise method.
Each child class must have at least one unique property (e.g. Breed, Color, AmountOfGold).
Each child class must have at least one unique method (e.g. Fetch, Graze, BreathFire).
Create at least one instance for each child class and call the set methods in each one to populate/initialize them.
Step 3 Polymorphism Part 1
Create an array of CAnimal* called paclsZoo of at least size 5.
Populate the zoo with pointers to the child class instances created in the previous step. Youll need to explicit cast the pointers/addresses.
Set at least one cell in the array to 0/null.
Step 4 Polymorphism Part 2
Write a FOR loop that will loop through the zoo and for each non-null cell print the animal name, type and call the MakeNoise method. Make sure that the correct child-specific information is displayed.
Step 5 Polymorphism Part 3
Write a FOR loop that will loop through the zoo and for each non-null cell explicitly cast the pointer into the child class specific type and call the unique child class method. Youll need to string compare the animal type in order to make the correct cast.
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