Question: C++ Can some explain why the function isPalindrome_type3 does not delete the white spaces from the string parameter. For example race car should come back
C++
Can some explain why the function isPalindrome_type3 does not delete the white spaces from the string parameter. For example "race car" should come back true for being a palindrome because if you erase the space it is the same word if reveresed. However it doesnt seem to work. The following is my code
#include
using namespace std;
void removeCharsFromString( string &str, char* charsToRemove ) { for ( unsigned int i = 0; i
bool isPalindrome_type1(string & aString) //test to see if a string is an exact palindrome { string temp; temp = aString; reverse(temp.begin(), temp.end()); return temp == aString; }
bool isPalindrome_type2(string & aString) //converts all char to lowercase then calls func isPalindrome_type1 { string allLow(aString); transform(aString.begin(), aString.end(), allLow.begin(), ::tolower); return isPalindrome_type1(allLow); }
bool isPalindrome_type3(string & aString) //removes all punctuation and space characters then call func isPalindrome_type2 { string temp(aString); char chars[] = " ,.!?"; removeCharsFromString(temp, chars);
return isPalindrome_type2(temp); }
int main() { string palindrome; cout > palindrome;
if(isPalindrome_type3(palindrome)) { cout

I want the second one to also come back as a palindrome.
thanks
string.cpp String.h Ja.out-"emma emmang:~/workspace $g++ passby.cpp emmang:~/workspace $./a.out Check for a palindrome: Please enter a phrase race..?car This is a palindrome emmang:~/workspace $./a.out Check for a palindrome: Please enter a phrase race car This is not a palindrome emmang:~/workspace $
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
