Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What occurs in each stage of the audit life cycle?

Answered: 1 week ago