Question: [c++] Given the following classes and code, what is the output of the program? Explain how you get the answer in detail and if any

[c++] Given the following classes and code, what is the output of the program? Explain how you get the answer in detail and if any problems what can be done to fix it.

class Pet

{

public:

Pet();

Pet(string);

void print();

private:

string name;

};

Pet::Pet() {

name = "";

}

Pet::Pet(string newName) {

name = newName;

}

class Dog: public Pet

{

public:

Dog(); Dog(string, string);

void print();

private:

string breed;

};

Dog::Dog() : Pet(), breed("") {

}

Dog::Dog(string newName, string newBreed) : Pet(newName), breed(newBreed)

{

}

void Pet::print()

{

cout << "My name is " << name;

}

void Dog::print()

{

Pet::print();

cout << ", and my breed is a "<< breed << endl;

}

int main() {

Pet* pPet;

Dog* pDog = new Dog("Rover", Doodle);

pPet = pDog;

pPet->print();

return 0; }

a. My name is Rover, and my breed is a Doodle

b. My name is Rover

c. , and my breed is a Doodle

d. Nothing

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!