Define a Pet class that stores the pet’s name, age, and weight. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getLifespan that returns a string with the value “unknown lifespan.”  Next, define a Dog class that is derived from Pet. The Dog class should have a private member variable named breed that stores the breed of the dog. Add mutator and accessor functions for the breed variable and appropriate constructors. Redefine the getLifespan function to return “Approximately 7 years” if the dog’s weight is over 100 p

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 1PE: In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain...
icon
Related questions
Question

Define a Pet class that stores the pet’s name, age, and weight. Add appropriate
constructors, accessor functions, and mutator functions. Also define a function
named getLifespan that returns a string with the value “unknown lifespan.”
 Next, define a Dog class that is derived from Pet. The Dog class should have a
private member variable named breed that stores the breed of the dog. Add mutator and accessor functions for the breed variable and appropriate constructors.
Redefine the getLifespan function to return “Approximately 7 years” if the dog’s
weight is over 100 pounds and “Approximately 13 years” if the dog’s weight is
under 100 pounds.
 Next, define a Rock class that is derived from Pet. Redefine the getLifespan
function to return “Thousands of years.”
 Finally, write a test program that creates instances of pet rocks and pet dogs that
exercise the inherited and redefined functions.

 

use c++

Expert Solution
steps

Step by step

Solved in 4 steps with 5 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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr