Question: Question 2 (30 points) Write a program that uses inheritance and polymorphism. Make a Pet class and let it have a kind of food (string).

Question 2 (30 points) Write a program that uses inheritance and polymorphism. Make a Pet class and let it have a kind of food (string). You have a feed() function and a speak() function. Both functions should be virtual functions. Child classes will have different things depending on what it is. Inside the four child classes, you should override the feed() and speak() functions to generate the specified output. Below is the main() function of your program: int main() t Pet nick, *jeff, *chris, *sam; nick new Cat ("Meow Mix", "blue"); jeff new Monkey ("Banana", false); chris- new Lizard("Flies", 5) sam = new Turtle ("Lettuce", 0.5); nick->feed jeff->feed ( chris->feed ) sam->feed ); nick->speak ) jeff->speak ); chris->speak ); sam->speak (); return 0 The output of the program: ot a blue cat ot a monkey with no tail ot a lizard with a 5cm tongue ot a 0.5-pound turtle Eats Meow Mix Eats Banana Eats Flies Eats Lettuce eow! Scratches pit ur
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
