Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ EXERCISE (DATA STRUCTURES). Please help me to figure out. Show clearly all the works and all the files included. Thanks Problem: Use a stack

C++ EXERCISE (DATA STRUCTURES). Please help me to figure out. Show clearly all the works and all the files included. Thanks

Problem: Use a stack to determine if a string is a palindrome

- Write a program that prompts the user to input a string of characters

- Each character is pushed on a stack: Therefore a Stack class must be declared in a Stack.h file

- Each character is also placed in a character array named: letters

- The characters are then popped off the stack and displayed on the screen: By doing so, the input string is

displayed in reverse order, because the first character popped off the stack is the last letter of the input string

- As each character is being popped off the stack, it is compared to the characters in the letters array :

Therefore, as the process begins, the first character in the letters array is compared to the first letter popped

off the stack(which is actually the last letter in the input string).

- The process of popping and comparing match all the characters in the letters array, then an output statement says that the

input string is a palindrome: Otherwise, it says that it is not a palindrome.

HINT: Use two functions: getString and isPalindrome

getString() function - Prompts the user to enter a string. Note: Use cin.get() in a while loop to read one character at a time. The loop should stop when the enter key (' ') is encountered.

parameter: Pass the stack object by reference

- Pass the letters array

isPalindrome() - Compares the items on the stack to the items in the letters array.

parameter: Pass the stack object by reference

- Pass the letters array

HERE IS OUTPUT :

Enter a string of characters : racecar -> getString() function

Here it is in reverse: racecar

It is a palindrome -> isPalindrome() function

.....

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions