Homework 2, Notlob?.
Short Description:
Write a program that classifies strings as palindromes.
This assignment is worth 20 points.
Goals
When you finish this homework, you should:
- Refreshed your programming skills.
- Strengthened your ability to use functions.
- Sharpened your skills manipulating strings.
- Used the [] operator associated with strings.
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. For the purposes of this program if ispunct returns true, the letter is punctuation.
- 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.
- 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 may still compare characters directly.
- This code must compile on one of the cslab machines with gcc version 5 or higher
- These are the machines in the lab.
- Try g++ --version to see the version of your compiler.
- Do not use cslab100 or cslab101
- This code must compile without warnings or errors with the following compiler flags
- 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.
- You may not use the standard algorithm library, or any element from the standard container library other than a string.
- Write this code yourself, don't "google" a solution.
Required Files
The all source code required to perform the task described above.
Your tar file must contain
- A Makefile that builds the project.
- All source code files required to build the project.
Your tar file may contain
- Example input files
- Example output files
- Meta files such as README and Copyright
Your tar file MUST NOT contain
Submission
Submit a tar file as an attachment to an email message to dbennett@edinboro.edu by class time on the due date.
The subject of this message should be CSCI 230 Homework 2 Submission.