Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. String Manipulation Working with text is a major task in a variety of computer science problems. Reading from files, data streams, or the user
3. String Manipulation Working with text is a major task in a variety of computer science problems. Reading from files, data streams, or the user requires examination and potentially manipulation of the input in order to transform the data into a useful form. To get a bit of practice you will start out working with palindromes. A palindrome is a word that reads the same backwards as forwards, Le. racecar, kayak, tacocat. In order to test whether a word is a palindrome or not, we need to test if the first letter is the same as the last letter, the second letter is the same as the second to last letter, and so on. For this program you will be writing a simple palindrome tester that will test three, four, and five letter words. First, you will need to prompt the user for a word of length three, four, or five and store that in a string. You will also need a Boolean variable, initialized to false, to store whether the user's word is a palindrome or not. Next, you will need to determine how many characters are in the palindrome using the length() function for a string. In the case of a five letter word, you will need to compare the first and last character, and the second and second to last character to see if they are the same. If they are, set the Boolean variable to true. You will need to similarly test four letter words and three letter words. If the word is more than five characters or less than three, you should alert the user of their mistake. Finally, based on the value of the Boolean variable, you should inform the user that their word was either a palindrome or that was not a palindrome or the wrong size. For example, if the user entered radar, your program should output that it was a palindrome. If the user entered radio, your program should output that it was either not a palindrome or the wrong size. If the user entered racecar, your program should output that it was either not a palindrome or the wrong size
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started