Answer to Question #337939 in C++ for Fei

Question #337939

Write a program using string functions that determine if the input word is a palindrome. A

palindrome word is a word that produces the same word when it is reversed.

Sample Input/output Dialogue:

Enter a word: AMA

Reversed: AMA

“It is Palindrome”

Enter a word: MAYOR

Reversed: ROYAM


1
Expert's answer
2022-05-08T14:33:10-0400
#include <string>
#include <algorithm>
#include <cctype>  
#include <iostream>
using namespace std;


int main()
{
    string str,strTest;
    int i=0,j=0;
    cout<<"Enter a word: ";
    getline(cin, str);
    int len= str.length();
    
    string rev = string(str.rbegin(),str.rend());
    
      for(i=0;i<len;i++)
        if(str[i]!=' ')
           strTest.push_back(toupper(str[i])); 
           
    cout<<"Reversed: "<<rev<<endl;
    
    if (equal(strTest.begin(), strTest.begin() + strTest.size() / 2, strTest.rbegin()))
        cout <<  "It is a Palindrome!";
    
    cout << endl << endl;
    return 0;
}

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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS