#include #include using namespace std; int read_names(string* &names); void print_names(string *names, int count); int main() { string *pet_names = nullptr; int count = read_names(pet_names); print_names(pet_names, count); delete[] pet_names; return 0; } int read_names(string* &names) { int count; cout << "How many? "; cin >> count; names = new string[count]; // create the dynamic array // Loop to read the names. for (int i = 0; i < count; i++) { cout << "Name #" << i+1 << "? "; cin >> names[i]; } return count; } void print_names(string *names, int count) { string *p = names; // p also points to the names array // Print the names forwards. cout << endl << "Names printed forwards:" << endl; while (count > 0) { cout << *p << endl; count--; p++; // point p at the next array element } // p now points beyond the end of the array. Do not dereference! // Print the names backwards. cout << endl << "Names printed backwards:" << endl; do { p--; // point p at the previous array element cout << *p << endl; } while (p != names); }