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

C++ Define a member function PrintAll() for class PetData that prints output as

ID: 3767457 • Letter: C

Question

C++

Define a member function PrintAll() for class PetData that prints output as follows. Hint: Make use of the base class' PrintAll() function.

#include <iostream>
#include <string>
using namespace std;

class AnimalData {
public:
void SetName(string givenName) {
fullName = givenName;
};
void SetAge(int numYears) {
ageYears = numYears;
};
// Other parts omitted

void PrintAll() {
cout << "Name: " << fullName;
cout << ", Age: " << ageYears;
};

private:
int ageYears;
string fullName;
};

class PetData: public AnimalData {
public:
void SetID(int petID) {
idNum = petID;
};

// FIXME: Add PrintAll() member function

/* Your solution goes here */

private:
int idNum;
};

int main() {
PetData userPet;

userPet.SetName("Fluffy");
userPet.SetAge (5);
userPet.SetID (4444);
userPet.PrintAll();
cout << endl;

return 0;
}

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

class AnimalData {

public:

void SetName(string givenName) {

fullName = givenName;

};

void SetAge(int numYears) {

ageYears = numYears;

};

// Other parts omitted

void PrintAll() {

cout << "Name: " << fullName;

cout << ", Age: " << ageYears;

};

private:

int ageYears;

string fullName;

};

class PetData: public AnimalData {

public:

void SetID(int petID) {

idNum = petID;

};

// FIXME: Add PrintAll() member function

/* Your solution goes here */

void PrintAll()

{

AnimalData::PrintAll();

cout << ", ID: " << idNum;

}

  

  

private:

int idNum;

};

int main() {

PetData userPet;

userPet.SetName("Fluffy");

userPet.SetAge (5);

userPet.SetID (4444);

userPet.PrintAll();

cout << endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote