Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program should be formed by C++ Write a program that allows the user to ente

ID: 3688382 • Letter: T

Question

The program should be formed by C++

Write a program that allows the user to enter a string as an input and then will recognize whether the string entered is palindrome or not. A palindrome is a string that can be read the same w ay from the left and from the right. For example: "madam" and "Able w as I ere I saw- 1'lba" are palindromes. You are going to implement this function using a single stack to check for palindromes. The function takes as an argument a string data type. Make sure that your program handles properly the comparison of upper and lower case characters

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
int main()
{
  
   char str[80];
   bool p,q;
   q = true;
       do
        {
       p = false;
       cout << "Enter string: ";
        getline(cin, str);
           for (unsigned int i = 0; i < str.size(); i++)
               {
                   if (str[i] < 65 || str[i] > 90 && str[i] < 97 || str[i] > 122)
                       {
                           p = true;
                       }
               }
        } while (p);

       for (unsigned int i = 0, j = input.size() - 1; i < input.size(); i++, j--)
       {  
           if (str[i] != str[j] && str[i] + 32 != str[j] && str[i] - 32 != str[j])
           {
      
               q = false;
               break;
           }
       }

       if (q)
       {
           cout << "The entered string is a palindrome." << endl;
       }
  
       else
       {
           cout << "The entered string is not a palindrome." << endl;
       }
   return 0;
}