Lexington High School Mathematics Math Dept. Front Page  | Student Links  | Family Links 
Introduction to C++, Kevin Kelly Kelly Front Page  | C++ Course Guide | C++ Assignments | C++ Info

Assignment 33: Palindromes

due Wednesday 5/29

A palindrome is a word or a phrase whose letters read the same forward or backward. Examples include the word level and the sentence Ma had a ham. (In the second example, note that capitalization, punctuation, and spacing are ignored. It's just the letters that matter; they are mahadaham, either forward or backward.)

Your assignment is to write and test a function

bool palindrome(apstring text)
that returns true if the string text is a palindrome, and false if it is not.

For the basic part of the assignment, you may write a function that works only for inputs of a single word made of only lowercase letters. Here are the test values for this part of the assignment:


Extension

The extension is to make the palindrome function ignore capitalization, punctuation, and spacing. You may succeed at some or all of these parts. To earn some or all of the extension points, please include a comment at the top of your program explaining which situations the program handles correctly.

You may find it helpful to #include<ctype.h> which enables various functions for determining the type of a character (isalpha(c), isdigit(c), etc.) and for converting cases (toupper(c), tolower(c)). For a list of all of these functions, type man ctype at your command prompt, or see this reference page.

Additional test values for the extensions:

Of course, the test values must be typed exactly as shown.




Adapted from Litvin and Litvin, "C++ for You" textbook, page 216.