Write a program named lab9 that determines if a given string is a palindrome. A
ID: 3634131 • Letter: W
Question
Write a program named lab9 that determines if a given string is a palindrome. A palindrome is a word or phrase that reads the same backward as forward. Blank, punctuation marks and capitalization do not count in determining palindromes. Here is some examples of palindromes:Radar
Too hot to hoot
Madam!I'm adam
A man, A plan, A canal-Panama
Doc, note, I dissent! A fast never prevents a fatness; I diet on cod
Output sample
Input a string:
Radar
It's a palindrome.
Input another string (y/n)?
y
Too hot to hoot
It's a palindrome.
Input another string(y/n)?
y
Hello world
It is not a palindrome.
Input another string(y/n)?
n
Hint
Create a string variable (char str[80])
Convert the string to uppercase characters
Keep only the alphabetic characters.
Compare the first character with the last character. If they're are the same,
compare the next character.
The program below is just a partial solution of the problem. The program provides some ideas on how to solve the problem, but you need to understand the logic solution. It's not a complete solution of the problem.
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{char str[80];
int strlength;
int j=0;
int front=0,back; int flag=1;
cin.getline(str, 80);
//Get the length of string str
strlength = -------------
//Convert all the characters in the string str to uppercase
for(------------------------)
if(str[i])
str[i]=-----------------(str[i]);
//Remove all the special characters except letters a - z
for(------------------------)
if(--------------(str[i]))
{str[j] = str[i];
------------------}
str[j]= '';
//front index is pointed to the first character in the string str
front = 0;
//back index points to the last character in the string str
back = ------------------;
//Compare the first character with the last character. If they're are the same,
//compare the next character.
for(i=0; i< j/2 ;i++)
{if(str[------] != str[---------])
{ flag = 0;
break;
}
front----;
back=back -1;
}
if(flag ---------- 0)
cout<<"It is not a palindrome"<<endl;
else
cout<<"It's a palindrome"<<endl;
return 0;
}
Explanation / Answer
// Write a program thatdetermines if a given string is a palindrome. #include #include #include using namespace std; int main() { char str[80]; //str1[80] will keep only thealphabetic characters of str[80]. char str1[80]; char ch = 'y'; while(ch != 'n' && ch != 'N'){ coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.