Problem

The following is an attempt to create a class to represent information about pets:class Pe...

The following is an attempt to create a class to represent information about pets:

class Pet{public:       Pet();       void printDescription();       string name;       int type;       bool neuterSpayed;       bool talks;};Pet::Pet() : type(0), neuterSpayed(false), talks(false){ }void Pet::printDescription(){        switch (type)        {        case 0:          cout << "Dog named " << name << endl;          cout << "Neuter/Spayed: " <<                  neuterSpayed;          break;          case 1:          cout << "Cat named " << name << endl;          cout << "Neuter/Spayed: " <<                  neuterSpayed;          break;        case 2:          cout << "Bird named " << name << endl;          cout << "Talks: " << talks << endl;          break;              }          cout << endl;}

Rewrite this code using inheritance. You should have a Pet class with subclasses for Dog, Cat, and Bird. Variables should be associated with the appropriate classes, defined as private when appropriate, and have appropriate functions to access the variables. Rewrite the printDescription function as a virtual function. There should no longer be the need for a switch statement or a type variable.

Write a main function that creates a vector or array of pets that includes at least one bird, one dog, and one cat, and then loops through and outputs a description of each one.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 15
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT