Basic Structure

You will be writing a program that tests strings to see if they are palindromes: sentences or phrases that spell the same thing whether read forwards or backwards, ignoring spaces, case, and punctuation. For example, one of the classic palindromes is "Madam, I'm Adam."

At the bottom of this page is a rough template for your program: copy it as your starting point. A quick outline of what it does:

  1. Calls a function to prompt the user with a string, then read a line of text from the user into the provided array, with the given length limit.
  2. Calls a function to test whether the entered string is an palindrome.
  3. Prints out the results of the palindrome test.

We will be fleshing the main function out in Step 5 (so this is an example of bottom-up programming). We will develop each of the subfunctions first, in the following steps.

Use the following as the starting skeleton for your program:


#include <iostream>

// ADD #include's HERE FOR ANY OTHER LIBRARIES YOU USE

using namespace std;

// ADD ANY GLOBAL CONSTANT HERE

int main(int argc, char *argv[]) {

    // For following to work you must be sure to define MAX_STR above
    // as a global constant (it must be global because it is used again
    // elsewhere).

    char buffer[MAX_STR];



    // First, prompt for, and get sentence to test from user, reading
    // it into buffer[]
    getAnswerFromUser( ... );

    // Now, test the inpu string to see if it's an palindrome
    _______ = testForPalindrome( ... );

    // Lastly, see what testForPalindrome() returned, and use that
    // to output the proper result

    ...  // SOME CODE HERE

    return 0;
}

//
// NOW, ADD YOUR OTHER FUNCTIONS HERE
//   (Do not put it ABOVE main()! )
//