Question: How can i get my code below to show Able was I, ere I saw Elba. a strict palindrome attributed to Napoleon A man, a

How can i get my code below to show Able was I, ere I saw Elba. a strict palindrome attributed to Napoleon
A man, a plan, a canal: Panama! an ordinary palindrome and a not palindrome fixed here is my code #include
#include
#include
#include
#include
using namespace std;
bool is_ordinary_palindrome(const string& str){
// make a copy of the input string in which punctuation and spaces are removed and all text is lower case
string copy;
for (char c : str){
if (isalnum(c)){// check if the character is alphanumeric
copy += tolower(c, locale::classic()); // append the lower case version of the character to the new string using the default locale
}
}
// make another copy of the input string in which all text is lower case
string lower = str;
for (char& c : lower){
c = tolower(c, locale::classic()); // convert each character to lower case using the default locale
}
// reverse the second copy
reverse(lower.begin(), lower.end());
// compare the first copy with the second copy
return (copy == lower);
}
bool is_strict_palindrome(const string& str){
// make a copy of the input string in which all text is lower case
string lower = str;
for (char& c : lower){
c = tolower(c, locale::classic()); // convert each character to lower case using the default locale
}
// make another copy of the input string
string reversed = lower;
// reverse the copy
reverse(reversed.begin(), reversed.end());
// compare the input string with the reversed copy
return (lower == reversed);
}
bool is_not_palindrome(const string& str){
// return the opposite of the ordinary palindrome check
return !is_ordinary_palindrome(str);
}
int main(){
string input;
do {
cout << "Please enter a string (Q to quit): ";
getline(cin, input);
if (input =="Q"){
break;
}
if (is_ordinary_palindrome(input)){
cout << "The string is an ordinary palindrome." << endl;
}
else if (is_strict_palindrome(input)){
cout << "The string is a strict palindrome." << endl;
}
else if (is_not_palindrome(input)){
cout << "The string is not a palindrome." << endl;
}
} while (true);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!