Description In this homework, you will write a C++ 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. Child classes will have different things depending on what it is. Below is the main() function of your program: int main() { 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; Show Transcribed Text The output of the program: Got a blue cat Got a monkey with no tail Got a lizard with a 5cm tongue Got a 0.5-pound turtle Eats Meow Mix Eats Banana Eats Flies Eats Lettuce Meow! *Scratches pit* Grrrrrrr *Turtle noise* 3 C

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Description In this homework, you will write a C++ program.............

Description
In this homework, you will write a C++ 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. Child classes will have different things depending on what it is. Below is
the main() function of your program:
int main() {
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;
Show Transcribed Text
The output of the program:
Got a blue cat
Got a monkey with no tail
Got a lizard with a 5cm tongue
Got a 0.5-pound turtle
Eats Meow Mix
Eats Banana
Eats Flies
Eats Lettuce
Meow!
*Scratches pit*
Grrrrrrr
*Turtle noise*
ů
Transcribed Image Text:Description In this homework, you will write a C++ 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. Child classes will have different things depending on what it is. Below is the main() function of your program: int main() { 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; Show Transcribed Text The output of the program: Got a blue cat Got a monkey with no tail Got a lizard with a 5cm tongue Got a 0.5-pound turtle Eats Meow Mix Eats Banana Eats Flies Eats Lettuce Meow! *Scratches pit* Grrrrrrr *Turtle noise* ů
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning