#include #include using namespace std; typedef string *StringPtr; int read_names(StringPtr& names); void print_names(StringPtr& names, int count); /** * Main */ int main() { StringPtr pet_names = nullptr; int count = read_names(pet_names); print_names(pet_names, count); delete[] pet_names; return 0; } int read_names(StringPtr& 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(StringPtr& names, int count) { StringPtr 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); }