C++ Program Question: Program will accept a string of characters and report whet
ID: 675329 • Letter: C
Question
C++ Program Question:
Program will accept a string of characters and report whether or not that string represents a palindrome. Examples (text in bold is user input):
Palindrome Recognizer:
Enter string : abba
abba is a palindrome. [and a great 70’s-80’s rock group]
Enter string : Never odd or even
Never odd or even is a palindrome.
Enter string : accurate
accurate is not a palindrome.
[Note: In all the examples multiple examples shown are for demonstration only, the code should ask for one string, report the results, and return to the main menu]
The program will read in an entire line of text (not just up to the first space). It will then remove the spaces, punctuation, and normalize the case of the letters (i.e. make them all upper or all lower case). It will then check to see if the resulting string is a palindrome. If so, print out <original string> is a palindrome. If the resulting string is not a palindrome, print out <original string> is not a palindrome.
Explanation / Answer
#include<iostream.h>
#include<string.h>
int main(){
char *str,*rev;
int i,j;
cout<<" Enter a string:";
cin>>str;
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='';
if(strcmp(rev,str))
cout<<str<<" is not a palindrome";
else
cout<<str<<" is a palindrome";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.