Question: Write a program (c++) that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it
Write a program (c++) that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit.
Your program must have (and use) at least four VALUE RETURNING functions. Start out by writing your own reverse, uppercase and filter functions. You should write:
A reverse function that takes a string and returns it in reverse order. (IN THE SLIDES)
This is a test 123! !321 tset a si sihT
An uppercase function that takes a string and returns it all uppercase.
This is a test 123! THIS IS A TEST 123!
A filter function that filters a string by returning only the letters and numbers of the string. (IN THE SLIDES)
This is a test 123! Thisisatest123
Then write a boolean function that uses the above functions to see if the given string is a palindrome.
A palindrome checker function that returns true if the passed string is a palindrome or returns false otherwise.
This is a test 123. false
Do geese see god? true
Note, this function should use the previous functions (uppercase, reverse and filter) to do its work
A string is a palindrome if it is the same forwards and backwards (once you uppercase it and filter out the non letters and numbers)
string fu = filter(uppercase(s));
if ( fu == reverse(fu) ) // it is a palindrome
Finally, write a driver function (either in main or in its own function) that has a loop to keep asking the user for strings to check, calls the palindrome checking function and has a counter to count the sentences and palindromes. When the user types END, the program should print out the # of sentences and # of palindromes and quit.
Sample run:
| Enter a string: Do geese see God? Do geese see God? is a palindrome Enter a string: This is just junk This is just junk is NOT a palindrome Enter a string: Murder for a jar of red rum. Murder for a jar of red rum. is a palindrome Enter a string: Some men interpret nine memos. Some men interpret nine memos. is a palindrome Enter a string: Never odd or even. Never odd or even. is a palindrome Enter a string: 1111111 1111111 is a palindrome Enter a string: END There were 6 sentences entered. There were 5 palindromes found. |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
