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. You’ll 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. You’ll need to string compare the animal type in order to make the correct cast. Can someone please help solve it.
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. You’ll 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. You’ll need to string compare the animal type in order to make the correct cast.
Can someone please help solve it.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 4 images