Refer the previous problem. In that problem, the definition of palindromes was r
ID: 3621746 • Letter: R
Question
Refer the previous problem. In that problem, the definition of palindromes was restricted to just perfect palindromes-every letter and blank exactly the same in both forward and backward versions. Now using arrays, expand the definition to ignore blanks, punctuations, and letter case. Thusmadam I'm Adam
becomes
madamimadam
which is now a plaindrome. Write a C++ program that reads a line of input and checks wheter it is a palindrome on the basis of this less restrictive definition. Output the reversed line, with all blanks and puncutation removed, and all letters converted to lowercase along with the program's decision.
I already have this part:
#include<iostream>
#include<string>
using namespace std;
int main ()
{
string str;
cout << "Enter string: " << endl;
getline(cin,str);
cout << endl;
string str2, str3;
int p=1;
int k = str.length()-1;
int y = k;
for(int i = 0; i <= (str.length()-1); i++,k--)
{
str2 = str.substr (i,1);
str3 = str.substr (k,1);
cout << str2 << str3 << endl;
if(str2.compare(str3)!=0)
{
p=0;
break;
}
}
if(p)
cout << endl << str << ": is a palindrome." << endl << endl;
else
cout << endl << str << ": is not a palindrome." << endl << endl ;
system("PAUSE");
return 0;
}
Explanation / Answer
Hope this helps. Let me know if you have any questions. Please rate. :) #include #include using namespace std; int main () { string str; 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.