Homework 3 Project 1, Notlob?.
Short Description:
Write a program that classifies strings as palindromes.
Goals
When you finish this homework project, you should:
- Refreshed your programming skills.
- Strengthened your ability to use functions.
- Sharpened your skills manipulating strings.
- Used the [] operator associated with strings.
- Placed library functions in a file different from the main.
- Used strongly enumerated types.
The main goal of this assignment is to make sure you can manipulate strings.
Formal Description
Write a program which reads phrases from a file and classifies the phrases as one of the following:
- Perfect Palindrome: The entire phrase is the same forward and backwards. racecar and god saw I was dog are perfect palindromes.
- Natural Palindrome: The phrase is the same forward and backwards but there may be additional punctuation or the case of the letters may differ. I did, did I? and Able was I ere I saw Elba are examples of natural palindromes.
- Palindrome: The letters only are the same forwards and backwards, there may be other non-letter characters, including spaces, in the phrase. A man, a plan, a canal: Panama. and Madam, I'm Adam. are examples of palindromes.
- Non-palindrome: None of the above. Hello world! and spam are examples of non-palindromes.
Your program should begin by requesting the name of the input file with the following prompt:
Enter the file name =>
Note, this prompt does not include the newline character. However, after you have read the file name, please print a newline character.
If the file does not exist, your program should print the following message and exit:
The file XXXXXXX does not exist.
Where XXXXXXX is the given file name.
If this file exists it will contain one phrase per line. Your program should read each phrase from the file. The program should then classify the phrase as a palindrome according to the above definitions. Finally the program should print the phrase, in quotation marks, followed by the words is a , the classification and a period. The phrase should be printed exactly as it was in the file and the classification should be all lower case.
For example, if the input file contains:
racecar
god saw I was dog
I did, did I?
Able was I ere I saw Elba.
A man, A plan, A canal: Panama!
Madam, I'm Adam.
Hello World!
spam
The output should be:
Enter the file name=> input.txt
"racecar" is a perfect palindrome.
"god saw I was dog" is a perfect palindrome.
"I did, did I?" is a natural palindrome.
"Able was I ere I saw Elba." is a natural palindrome.
"A man, A plan, A canal: Panama!" is a palindrome.
"Madam, I'm Adam." is a palindrome.
"Hello World!" is a non-palindrome.
"spam" is a non-palindrome.
Discussion
- Phrases may be a single character or even empty. Both cases are perfect palindromes.
- IE: "A" is a perfect palindrome.
- The most restrictive classification that applies should be used. A perfect palindrome is also a palindrome, but it should be classified as a perfect palindrome.
- Make sure you do not have the end of file bug.
- Make sure all output is spelled and formatted correctly.
- Since the purpose of this program is string manipulation, for this program only:
- You may not use the string comparison operators. You should write a
boolean function which takes two strings and returns true if they are the same.
- You may not use arrays or any container other than a string.
- You must define and use a scoped enumerated type in your program in a meaningful way.
- I would build an enumerated type to represent the types of palindromes.
- I would build a set of support functions to go with this.
- I would build a function that takes a string and returns one of your enumerators classifying the string.
- You must split your code into multiple files.
- I would have one set of files for the enumerated type.
- I would have another set of files for the palindrome related routines.
- I would have a main file to implement the logic of the program.
- This code must compile on cslab103
- If you wish, this Makefile might be useful.
- I used the functions ispunct and isalpha in my program.
- For more information man ispunct or search the internet.
- For this program punctuation is identified as anything ispunct identifies as punctuation.
- I also used toupper.
- I used palindromelist.net for the source of many of my palindromes.
- You should use good programming style
- Well documented, especially self documenting code.
- Constants when applicable.
- Reasonable identifiers.
- No function more than 20-30 lines.
- No repeated code.
- Make sure identifying information, including your name is in a comment at the top of your source code.
Required Files
A tar or zip file containing your source code and a Makefile.
If you need to communicate any additional information, please create a file called ReadMe. This is just a text file. Place it in your directory and include it in the tar/zip file.
Submission
Submit the assignment to the D2L folder Homework 3 by the due date.