Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given the following segment of code. All the following C++ questions are based on this code. class Owner { public: int iPhone; string

You are given the following segment of code. All the following C++ questions are based on this code.

class Owner { public: int iPhone; string sEmail; Owner(int phone, string email) { // constructor iPhone = phone; sEmail = email; } };

class Pet { public: string sName; Owner *pOwner; Pet(string name, int phone, string email) { // constructor sName = name; pOwner = new Owner(phone, email); } };

class Cat : public Pet {

public: string cBreed;

int iAge;

Cat(string name, int phone, string email, string breed, int age) . . . // write the constructor

};

class PetNode { public: PetNode *pNext; Pet *pNode; PetNode() { pNode = NULL; pNext = NULL; }; } *head = NULL; // head is the global pointer to the PetNode linked list

void insertPet(); void insertCat(); //...

void main(void) { Pet* p; Cat* c; PetNode* pn; // input the data here insertPet(); insertCat(); // ... }

The following diagrams show the relationships among the classes and an example of the linked list constructed using the classes.

image text in transcribed

1. Write the insertCat function to insert a Cat object into the linked list (whose nodes are of PetNode type). The start pointer of the linked list is head pointer. Insert the new node at the end of the linked list (as the last node). You do not have to write "Get" and "Set" functions to access the members of any class. You can directly access them. You can assume that the required input data are entered in the main program before calling the insertCat method. [7 points]

void insertCat(char *name, int phone, char *email, string breed, int age)

The following diagrams show the relationships among the classes and an example of the linked list constructed using the classes PetNode pNext pNode PetNode pNext pNode PetNode NULL pNode head Pet Owner containment sName - iPhone Pet powner- sEmail Pet CName inheritance cName pOwner sBreed pOwner pOwner sBreedOwner Age iPhone iPhone iPhone Age cEmail cEmail cEmail

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

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions