Answered step by step
Verified Expert Solution
Question
1 Approved Answer
WRITE C++ Palindrome Checker Assignment A palindrome is a word, or set of words, that read the same forwards and backwards, like mom, radar, and
WRITE C++
A palindrome is a word, or set of words, that read the same forwards and backwards, like mom, radar, and was it a cat I saw? This sounds like a good use for a stack!
You are going to write a program that accepts a string from the user and checks to see if it is a palindrome and report the results.
Create a function called IsPalindrome that accepts a string and returns true if the string is a palindrome and false is it is not.
The main program should ask the user for a string. Remember a string can contain spaces! The main should pass the string to the isPalindrome function and report is the string is a palindrome or not, not just output 1 or 0.
Some hints for the isPalindrome function:
Pass the function a parameter, well call it message
Create a stack of the char data type
We have to account for spaces, so we need a loop that looks at each character in the string (you can use the message.at(x) function) and checks if it is not a space. If not, push the character onto the stack
We now have the string forward (message) and backwards (on the stack). We need a loop to look at each character in the string. If that is not a space, compare it to the top of the stack. If they arent the same, return false, otherwise pop the character off the stack. If we make it through the loop, return true
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