Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

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

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions