//CS2310 Exercise 13 // //Chapter 15: p893 - 8 //Given the declarations: // //int numLetters; // No. of letters in user's last name //int i; // Index variable //char* name; // Pointer to array of letters in // user's last name // //Write a section of code that prompts the user for the //number of letters in his or her last name, dynamically //creates a char array of exactly the right size to hold //the letters, inputs the letters, prints out the letters //in reverse order (last through first), and deallocates //the array. #include #include using namespace std; int main () { int numLetters; // No. of letters in user's last name int i; // Index variable char* name; // Pointer to array of letters in // user's last name cout << "Enter the no. of letters in your last name: "; cin >> numLetters; cin.ignore(10,'\n'); name = // Write the necessary code here to allocate engough // memory to hold the name to be inputed. cout << "Enter your last name: "; for (i = 0; i < numLetters; i++) cin.get(name[i]); name[i] = '\0'; cout << "Your name in normal order:" << name << endl; cout << "Your name in reverse order:"; for (i = numLetters - 1; i >= 0; i--) cout << name[i]; delete // Write necessary code here to free the array // pointed to by viriable "name" return 0; }