Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions