Implement a class named Animal has two private member variables: name of type string and numLegs of type int, and has the following member functions: • setName—Function to set the name • setNumLegs—Function to set the number of animal legs • getName—Value-returning function to return the name • getNumLegs—Value-returning function to return the number of animal legs • speak()—Value-returning function to return the empty string • move()—Value-returning function to return the empty string • print()—Outputs the data stored in the instance variables with the appropriate titles • Constructor with parameter—Sets the values of the instance variables to the values specified by the user, in default: sets name to the empty string and number of legs to 0 2. Using an Animal class as a base class, implement two derived classes simulating a Cat and Dog, each redefining three functions constructor, speak(), move() to represent each animal the most suitable. 3. Write a function to handle the polymorphism in representing name, number of legs, speak, and move of three above classes’ instances. 4. Then write the main class that creates instances of three above classes (one for each class), and called the function written in 3. to demonstrate that name, number of legs, speak, and move were output correctly for each class instance

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 15RQ
icon
Related questions
Question

Implement a class named Animal has two private member variables: name of type string and numLegs of type int, and has the following member functions: • setName—Function to set the name • setNumLegs—Function to set the number of animal legs • getName—Value-returning function to return the name • getNumLegs—Value-returning function to return the number of animal legs • speak()—Value-returning function to return the empty string • move()—Value-returning function to return the empty string • print()—Outputs the data stored in the instance variables with the appropriate titles • Constructor with parameter—Sets the values of the instance variables to the values specified by the user, in default: sets name to the empty string and number of legs to 0 2. Using an Animal class as a base class, implement two derived classes simulating a Cat and Dog, each redefining three functions constructor, speak(), move() to represent each animal the most suitable. 3. Write a function to handle the polymorphism in representing name, number of legs, speak, and move of three above classes’ instances. 4. Then write the main class that creates instances of three above classes (one for each class), and called the function written in 3. to demonstrate that name, number of legs, speak, and move were output correctly for each class instance

 

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
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
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage