Stacks/STL
The goal of this lab is to give you a bit more experience with stacks. For this assignment you will use the stack class of the C++ Standard Template Library to determine if a given phrase is a palindrome. A palindrome is a phrase that reads the same backward and forward. Several examples can be found at the following URL: http://www.palindromelist.com/.
Create a new Project and add the following code to the project: stack.cpp. The code fragment prompts the user for a phrase and pushes each individual A-Z or a-z character onto a stack of chars. Your task is to use a second stack to determine if the phrase is a palindrome. The output of your program should either indicate "The phrase you entered is a palindrome" or "The phrase you entered is NOT a palindrome".
Hints
- The STL stack supports the functions push, pop, top, size, and empty. The interface can be found here: http://www.cppreference.com/cppstack/index.html. The thing to note is that pop does NOT return the popped item. Therefore, you will typically need to do a top to look at the item and then do a pop to remove it from the stack.
- If you use == or != to compare two characters, an uppercase character will NOT be the same as its corresponding lowercase character. You can use all lowercase characters to remedy this problem. For extra credit, modify your program so that it considers an upper and lower case version of the same character to be equal. You should refer to the following URL that provides the ASCII value for each character: http://www.lookuptables.com/.
- Make sure to test for all special cases. For example, "Damn! I, Agassi, miss again! Mad!" is slightly different from "Ah, Satan sees Natasha.".
Email me (srollins@mtholyoke.edu) your completed code by Friday, 4/21/06 - 5pm.
Sami Rollins