Implement a class person with the following fields: The name A pointer to the pe
ID: 3534887 • Letter: I
Question
Implement a class person with the following fields:
The name
A pointer to the person's best friend
A popularity counter that indicates how many other people have this person as their best friend.
The program reads in a list of names, allocates a new person for each of them, and stores them in a vector<Person*>. Then ask the name of the best friend for each of the person objects. Locate the object matching the friend's name and call a set-best-friend member function to update the pointer and counter. Finally, print out all Person objects, listing the name, best friend, and popularity counter for each.
Explanation / Answer
Your class person will look like this:
class Person
{
String name;
String* best_friend;
int pop_counter;
}
You can now simply create a vector of Person and store the details like this:
loop
{
//take input name;
Add the name in the persons vector
}
Cheers!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.