Question: 1. Perform the following exercises under lab4 sub directory. 2. Implement class Person with the following fields: the name a pointer to best friend (Person

1. Perform the following exercises under lab4 sub directory.

2. Implement class Person with the following fields:

the name

a pointer to best friend (Person *)

a popularity counter that indicates how many other people have this person as their best friend

Write a program that reads in a list of names, allocates an object of type Person for each name, and stores them in a vector of pointers: vector. The program then asks for name of the best friend for each Person, locates the object matching the friend's name, and calls set_best_friend() member function to update the pointer and counter. Finally, the program should print out all Person objects. This includes listing the name, best friend, and popularity count for each person.

The following three files implement most of the above functionality. Prior to running the program, make sure file names with a list of names already exists in your directory.

1. Perform the following exercises under lab4 sub directory. 2. Implement class

Person with the following fields: the name a pointer to best friend

(Person *) a popularity counter that indicates how many other people have

3. Draw the vector, objects, and pointers for file names

Jackie

Jack

Amanda

Rod

Connie

and input (from keyboard)

Jack

Sam

Jack

Connie

Rod

4. Modify the program to prevent duplicate names being inserted in the vector.

5. In what scenario does the check for null pointer in get_best_friend() become necessary? What would happen if the check was not there?

6. Modify the program to prompt the user for another name if best friend is not found.

please write the code as soon as possible

#ifndef PERSONH #define PERSONH - - // your name // Person.h // date // description #include using namespace std; class Person string name; Person best_friend; int popularity public: Person (): name( "), best_friend (0), popularity (0) Person (string n): name(n), best friend (), popularity(o) f string get_name (); string get_best_friend(); int get popularity); void set_best_friend (Person) #end if #ifndef PERSONH #define PERSONH - - // your name // Person.h // date // description #include using namespace std; class Person string name; Person best_friend; int popularity public: Person (): name( "), best_friend (0), popularity (0) Person (string n): name(n), best friend (), popularity(o) f string get_name (); string get_best_friend(); int get popularity); void set_best_friend (Person) #end if

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!