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. Implementclass Person with the following fields the name a pointer to bestfriend (Person *) a popularity counter that indicates how many other people

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 #ifndef PERSON H #define PERSON H // your name // Person.h // date / description #include using namespace std; class Person string name; Personbest friend; int popularity; public: Person(): name("), best_friend (0), popularity(0) Person (string n): name(n), best_friend (0), popularity(0) t string get_name0; string get_best_friend); int get popularity) void set_best friend (Person); #end if /1 your name // Person.cpp // date // description #include "Person . h" string Person: :get_name() return name string Person: :get_best_friend() if (best friend!- ) // check for null pointer else return "; Person: :get_popularity) return best_friend->name; return popularity; void Person::set_best_friend (Person bf) best friend bf; (bf->popularity)++; 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 #ifndef PERSON H #define PERSON H // your name // Person.h // date / description #include using namespace std; class Person string name; Personbest friend; int popularity; public: Person(): name("), best_friend (0), popularity(0) Person (string n): name(n), best_friend (0), popularity(0) t string get_name0; string get_best_friend); int get popularity) void set_best friend (Person); #end if /1 your name // Person.cpp // date // description #include "Person . h" string Person: :get_name() return name string Person: :get_best_friend() if (best friend!- ) // check for null pointer else return "; Person: :get_popularity) return best_friend->name; return popularity; void Person::set_best_friend (Person bf) best friend bf; (bf->popularity)++

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!