CMSC 201
Programming Project Four
Palindromes
Out: Monday 4/12/04
Due Date: Sunday 4/25/04, before midnight
The design document for this project,
design4.txt,
is due: Before Midnight, Sunday 4/18/04
|
The Objective
The purpose of this assignment is to give you practice with
recursion, strings and chars, string and char library functions,
arrays of strings, allocating memory dynamically, reading files,
and using command line arguments.
The Background
According to Webster's dictionary a palindrome
is defined as a word or sentence that is the same whether read
forward or backward, coming from the roots palin which means back
and drome which means running on.
The Task
Your assignment will be to determine whether a given word, phrase or
sentence is a palindrome. We will be providing a data file containing
many phrases, some of which are palindromes. You will also give the
user the option to look at some other statistics about each string: the
number of vowels and consonants, the length of the string, and how many
words each contains.
Program Requirements
- Your program must take the name of the text file to analyze as a
command-line argument. The file that contains the strings is
located on the GL system in the directory
/afs/umbc.edu/users/s/b/sbogar1/pub
The file is named strings.dat .
You should copy this file from this location into the directory you
will be using to work on this project. Do NOT cut and paste from this
link, since you may inadvertently alter the file by doing so.
- You will open the file, read from it, and close it using C's
file-handling functions.
- You will be storing these strings in an array of strings, for which you
must dynamically allocate memory. Since an array of strings is really
just an array of pointers to chars, you must also dynamically allocate
the memory necessary to store the characters of each string.
HINT:The addresses of the memory allocated for each of the
strings are what is stored as the elements of the array of strings.
- You will be using a two-level menu system in your program to first
allow the user to choose a string (1st level) and then allow the user
to choose which statistics to view (2nd level).
Menu specifications:
- You must have a recursive function called IsPalindrome() which
determines whether the string passed to it is a palindrome. It must
work recursively by calling itself with different arguments and may
NOT have any loops within it. It should return either TRUE or FALSE,
since it is a recursive predicate function. When determining whether
a string is a palindrome, you should ignore white space characters,
punctuation or any other characters that are not alphabetic. You
should consider the upper-case and lower-case versions of the same
letter to be the same letter. (i.e. they are equal).
- Since you will open the file, you must also close it, and you should
do this as soon as you are finished reading from it.
- Since you are dynamically allocating memory both for the array of
strings and the memory for each of the strings, you will need to free
this memory. Simply saying free(array); will NOT free all of the
memory that you have dynamically allocated, because it will not free
the memory that you allocated for each of the strings.
- You must use separate compilation for this project.
Other Hints & Guarantees
- You will be reading the entire contents of the file into an array of
strings. You must dynamically allocate enough space to hold that
array, but you don't know how big to make it. - You could open the file
and read one string at a time until you hit EOF keeping a count of the
number of strings as you go. You can get back to the beginning of the
file by using rewind().
- We guarantee that each string in the file will end with a newline
character and that the strlen() of no string will exceed 99 characters.
- We guarantee that the graders will enter only integers as their response
to the 1st-level menu and only characters as response to the 2nd-level
menu.
Sample Run
Here is a link to the sample output of this
program.
Submitting the Program
To submit your program, type the following command at the Unix prompt
submit cs201 Proj4 followed by the .c and .h files necessary for compilation
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show all files that
you submitted in a format similar to the Unix 'ls' command.
submitls cs201 Proj4