Question: Hello, I need code for the following assignment: Write a program using stacks that tests whether or not a word, expression or number is a

Hello, I need code for the following assignment: Write a program using stacks that tests whether or not a word, expression or number is a palindrome. A palindrome is a word or expression that reads the same forwards and backwards. I have part of the code but I am stuck. I know I am missing an if statement to compare the original and the new word. i also realize that i need to fill across. Help! See what I have below:

//This stack program tests spanish words under 15 characters to see if they // are palindromes or not.

#include

using namespace std;

int const maxstack = 15;

class stack_type

{

public:

void clear_stack();

bool empty_stack();

bool full_stack();

void push(char pal);

void pop(char pal);

char stack[maxstack];

int top;

};

//==============================================================================

int main()

{

stack_type p;

char i,palindrome;

p.clear_stack();

cout << "Enter a spanish word, up to 15 characters in length. " << "Enter a 0 at the end to quit. ";

cin >> palindrome;

while (! (p.full_stack()) && palindrome != 0)

{ p.push(palindrome); if (! (p.full_stack())) { cin >> palindrome; } } cout << "The word reads backwards: "; while (!(p.empty_stack())) { p.pop(palindrome); cout << palindrome << " "; } }

//============================================================================== void stack_type::clear_stack() { top = 0; } //============================================================================== void stack_type::push(char pal) { top = top + 1; stack[top] = pal; } //============================================================================== void stack_type:: pop(char pal) { pal = stack[top]; top = top - 1; } //============================================================================== bool stack_type::full_stack() { if (top==maxstack-1) return true; else return false; } //============================================================================== bool stack_type:: empty_stack() { if (top==0) return true; else return false; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!