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.
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 #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started