Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This a C++ advance assignment. Please complete in 48 hours, Thank you. The follo

ID: 3678975 • Letter: T

Question

This a C++ advance assignment. Please complete in 48 hours, Thank you.

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

#include <string>

using namespace std;

class Pet

{

public:

     Pet();

     void printDescription();

     string name;

     int type;

     bool neuterSpayed;

     bool talks;

};

------------------------------------------------

#include "Pet.h"

#include <iomanip>

#include <iostream>

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. Add variables that specific do each subclass. 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 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.

Please Complete and create a fully working program in visual studio. I need to copy and paste. provide instructions on how to do this. Thank You

Explanation / Answer

#include<iostream.h>
#include<conio.h>

class Pet
{
   private:
       char name[30];
       int age;
   public:
       void get_pdata ( )
       {
           cout<<"Enter the pet name:";
           cin>>name;
           cout<<" Enter the age:";
           cin>>age;
       }
       virtual void put_pdata ( )
       {
           cout<<"Display Results: ";
       }
};

class Dog : private Pet
{
   private:
       char property[200];
       char breed[50];
   public:
       void get_stdata ( )
       {
           get_pdata ( );
           cout<<" Enter property:";
           cin>>property;
           cout<<" Enter breed:";
           cin>>breed;
       }
       virtual void put_data ( )
       {
           cout<<"Name: "<<name;
           cout<<" Age: "<<age;

           cout<<" Property: "<<property;
           cout<<" Breed: "<<breed;
       }
};

class Cat : private Pet
{
   private:
       char sound[200];
       char breed[50];
   public:
       void get_stdata ( )
       {
           get_pdata ( );
           cout<<" Enter sound:";
           cin>>property;
           cout<<" Enter breed:";
           cin>>breed;
       }
       virtual void put_data ( )
       {
           cout<<"Name: "<<name;
           cout<<" Age: "<<age;

           cout<<" Sound: "<<Sound;
           cout<<" Breed: "<<breed;
       }
};


class Bird : private Pet
{
   private:
       int fly_speed;
  
   public:
       void get_stdata ( )
       {
           get_pdata ( );
           cout<<" Enter fly speed:";
           cin>>fly_speed;
       }
       virtual void put_data ( )
       {
           cout<<"Name: "<<name;
           cout<<" Age: "<<age;

           cout<<" Fly Speed: "<<fly_speed;
       }
};
void main ( )
{
   Pet *x [] = { new Dog(), new Cat(), new Bird(), new Dog() };
   int i;
   for(i=0;i<sizeof(x);i++)
       {
           x[i].get_stdata ( );
           x[i].put_fdata ( );
       }
   getch ( );
}