I need help on the following question, as the textbook solution provided in Cheg
ID: 3685345 • Letter: I
Question
I need help on the following question, as the textbook solution provided in Chegg does not work. Can someone provide an explanation as they write each line of code? Thank you!:
Exercise P7.1 in Big C++, 2nd Edition:
Implement a class Person with the following fields:
-the name
-a pointer to the person’s best friend (a 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 a new Person for each of them, and stores them in a vector. 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
#include #include #include using namespace std; class Person { private: string name; int age; public: Person(string n, int a); string get_name()const; int get_age()const; void increment_age(); void print()const; }; Person::Person(string n, int a) { name = n; age = a; } string Person::get_name() const { return name; } void Person::increment_age() { age += 1; } void Person::print() const { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.