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

Description: You are going to write a program that checks to see if a string is

ID: 3599911 • Letter: D

Question

Description: You are going to write a program that checks to see if a string is a palindrome A palindrome is a word, phrase, number, or other sequence of characters whic reads the same backward as forward, such as madam or race car. Sentence- length palindromes may be written when allowances are made for adjustments o capital letters, punctuation, or word dividers, such as "A man, a plan, a canal Panama!". " (Wikipedia) You will use a stack and a queue to determine if a phrase is a palindrome. You will ignore spaces and punctuation. You may use either a c-string or a c++ string. (Hint: You should store characters on the stack and queue to make this easy.) The stack class is written for you, but will need to be modified to use the correct type. You will need to write the queue class. The Node class will need to be modified to work with the stack and queue classes. The code to check to see if the string is a palindrome should be in the main function. You should have 2 test cases that you test in main-one that is palindrome and one that isn't. Then you should ask the user for a phrase until the user wishes to terminate.

Explanation / Answer

Program for palindrome

#include<iostream.h>

using namespace std;

#include "stack.h"

#include "Queue.h"

int main(void)

{

Stack s;

Queue q;

string letter;

int length;

cout<<"Please enter a series of characters."<<endl;

cin>>letter;

length=letter.size();

for(int i=0;i<length;i++)

{

q.enqueue(i);

s.push(i);

}

bool isPalindrome=true;

while(isPalindrome &&(!q.empty()) && (!s.empty()))

{

if(s.top() !=q.front())

{

isPalindrome=false;

}

else

{

q.dequeue();

s.pop();

}

}

if(isPalindrome ==false)

{

cout<<"Not a palindrome."<<endl;

}

else

{

cout<<"Is a palindrome."<<endl;

}

}