A palindrome is a word, a phrase, or a sentence that can
be read both the usual way (from left to right) and backwards
without changing its meaning. There are many palindromic words,
such as radar, madam and eye. There are phrases
that are perfectly palindromic ( Dennis sinned ), but usually
we agree to ignore spaces (word boundaries) and punctuation, and
look only at the letters themselves, so that Never odd or even,
or Rise to vote, Sir! are palindromes too.
You will write a program that decides if a string is a palindromic
sentence, and if it is a perfect palindrome (i.e. word boundaries
are preserved by reading it backwards). At first you will enter
your test phrases from standard input, then take them from a file.
To check whether a sentence is palindromic, you need to change
all letters to lowercase and then compactify the string by removing
all spaces and punctuation (leaving only a string of lowercase
letters). Then you need to check if the first character in the
condensed string is the same as its last character, the same for
the second and last-but-one characters, and so on.
C++ strings are described in detail on pages 91-93 of your textbook.
Files are described in Chapter 11 (see 11.4), and you can use
my Files Example program in the Examples folder
in the course directories. Start your work by dragging the Minimal
Project folder to your desktop. If you want to use any of the
nice CoreTools library functions, duplicate one of the existing
projects (Files Example will do) and work in it instead. Don't
forget to put #include <string> and #include <fstream.h>
at the head of your program if you are starting with the Minimal
project.
Proceed as follows:
Now you are ready to take input. Use
to input sentences from the keyboard ( cin >> your_string;
stops at the first whitespace, whereas you need to input strings
containing spaces).
Put the test file into your project folder -- that way you don't have to show the full path to it, just the file name is OK. Refer to my Files Example in the course directories.
I recommend that you look at http://stekt.oulu.fi/~jopi/humor/palindromes.html
for more information and fun facts about palindromes (longest
known palindromes, palindromic verse, palindromes in other languages
etc.). Also, this is a good page to find more palindromes for
your tests.