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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started