60 342
Assignments Done
98%
Successfully Done
In April 2018

Answer to Question #42159 in C++ for thabo Moletsane

Question #42159
A palindrome is a word or phrase that reads the same forwards and backwards, character for character,disregarding punctuation, case or spaces. Some examples are "racecar", "madam,I'm Adam".Write a program that allows the user to input a word or phrase and then determines if it is a palindrome.The program should use a Boolean Function procedure named Palindrome that returns the value True when the word or phrase is a palindrome and the value False otherwise
Expert's answer
//Answer on Question #42159 - Programming - C++ 
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
bool notIsalnum(int c) {
return !::isalnum(c);
}
bool Palindrome(const string& phrase) {
string s = phrase;
s.erase(remove_if(s.begin(), s.end(), notIsalnum), s.end());
transform(s.begin(), s.end(), s.begin(), ::toupper);
return s == string(s.rbegin(), s.rend());
}
int main() {
cout << "Input word or phrase: " << endl;
string phrase;
getline(cin, phrase);
cout << "\"" << phrase << "\" is ";
if (!Palindrome(phrase)) cout << "not ";
cout << "a palindrome" << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions