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

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.

image text in transcribed

image text in transcribed

image text in transcribed

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

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

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions