#include #include #include using namespace std; class Person { char* name; public: Person(const char *); // constructor ~Person(); void print() const; // display Person's name }; Person::Person(const char* n) : name(new char[strlen(n)+1]) { strcpy(name,n); } Person::~Person() { cout << "Person destructor call for " << name << endl; delete [] name; name = nullptr; } void Person::print() const { cout << name << endl; } class People { private: Person** array; int count; Person* addPerson(); // private member function public: People(int); ~People(); void print() const; }; People::People(int num) : array(new Person*[num]), count(num) { char temp[20]; for (int i = 0; i < num; i++) { cout<<"Enter the Person's name => "; cin >> temp; array[i] = new Person(temp); } } People::~People() { cout << "\nPeople destructor called" << endl; for (int i = 0; i < count; i++) { cout << "deleting pointer to Person[" << i << "]\n"; delete array[i]; } delete [] array; } void People::print() const { cout << "\nHere's the People:\n"; for (int i = 0; i < count; i++) array[i]->print(); } int main () { cout << "How many friends do you have? "; int numFriends; cin >> numFriends; People friends(numFriends); friends.print(); }