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
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
Related questions
Question
Description In this homework, you will write a C++
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 3 images
Knowledge Booster
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.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning