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

ASSIGNMENT: Write a program, which will ask for and read in a line of text chara

ID: 3639230 • Letter: A

Question

ASSIGNMENT:

Write a program, which will ask for and read in a line of text characters. The program will then determine if the line of text forms a palindrome and print whether it is or not. After printing this message, the program will ask for another line of text. The program will end when the line of text read matches the string “END” (letters in all caps).

NOTES:

1) When testing if the string is a palindrome, an upper and lower case character will be considered a match. Only when checking for END is there a requirement for the case to be specifically upper case.

2) The maximum number of displayable characters in a line will be 80.

BONUS: Do the program without use of any “str” methods – plus 10 points.

Explanation / Answer

please rate - thanks

#include<iostream>
#include <string>
using namespace std;
bool isPalindrome( char[] );
bool end(char[]);
int main()
{char input[81];
bool palin;
int i;
cout<<"Enter a string(END to exit): ";
cin.getline(input,81);
while(!end(input))
{
palin=isPalindrome(input);
if(palin)
   cout<<input<<" is a Palindrome ";
else
    cout<<input<<" is not a Palindrome ";
cout<<"Enter a string(END to exit): ";   
cin.getline(input,81);   
}
return 0;
}
bool end(char word[])
{if(word[0]=='E'&&word[1]=='N'&&word[2]=='D')
      return true;
return false;
}
bool isPalindrome( char input[])
{int i=0;
bool y=false;
int j;
for(j=0;input[j]!='';j++);
j--;
while(toupper(input[i])==toupper(input[j])&&i<=j)
      {
      i++;
      while(!isalpha(input[i]))
            i++;
       j--;    
      while(!isalpha(input[j]))
          j--;
       }
if(i>j)
    y=true;
return y;
}