Question: The existing code provides a class Person and sets up 5 generations of women. Maria is the daughter of Jan who is the daughter of

The existing code provides a class Person and sets up 5 generations of women. Maria is the daughter of Jan who is the daughter of Naomi who is the daughter of Nancy who is the daughter of Sue. Write code for the printGrandma function to print out the name of the grandmother of the Person p who is passed to the function.

#include #include

using namespace std;

class Person { private: Person* mother; //memory address of our spouse, nullptr = not married string name; public: Person(string nameValue, Person* motherPtr) { name = nameValue; mother = motherPtr; } Person* getMother() { return mother; }

string getName() { return name; } };

void printGrandma(Person& p) { //Do not modify anything on or above the line below this //YOUR_CODE_BELOW

//YOUR_CODE

//YOUR_CODE_ABOVE //Do not modify anything on or below the line above this }

int main() { Person p1("Sue", nullptr); Person p2("Nancy", &p1); Person p3("Naomi", &p2); Person p4("Jan", &p3); Person p5("Maria", &p4); printGrandma(p3); printGrandma(p4); printGrandma(p5); }

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!