C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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*
ů
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning