Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a program in C++. STACK and QUEUE ADT (TEMPLATES)Project: Project: Word-By-Word Palindromes. A word-by word palindrome is a string of words such that the

write a program in C++.

STACK and QUEUE ADT (TEMPLATES)Project:

Project: Word-By-Word Palindromes. A word-by word palindrome is a string of words such that the words read the same forward and backward. For example, the quote "abba aba" is a word level palindrome because it takes each word and makes sure it's the same forward as it is backward. Write a program to test input strings and tell whether or not they are word-by-word palindromes or not. Consider upper- and lowercase letters to be the same letter and have the program only consider letters and not symbols.

I have code so far where it tests the whole line to see if it's a palindrome or not. What I really want is to test each WORD and see if each INDIVIDUAL WORD is a palindrome. Somehow the program needs to look at the whitespace and check in between each whitespace whether the word is a palindrome or not. PLEASE HELP! WILL RATE!!! C++

Code:

// FILE: pal.cpp

// Program to test whether an input line is a palindrome. Spaces,

// punctuation, and the difference between upper- and lowercase are ignored.

#include // Provides assert

#include // Provides isalpha, toupper

#include // Provides cout, cin, peek

#include // Provides the queue template class

#include // Provides the stack template class

using namespace std;

int main()

{

queue q;

stack s;

char letter;

queue::size_type mismatches = 0; // Mismatches between queue and stack

cout

while (cin.peek() != ' ')

{

cin >> letter;

if (isalpha(letter))

{

q.push(toupper(letter));

s.push(toupper(letter));

}

}

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

{

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

++mismatches;

q.pop();

s.pop();

}

if (mismatches == 0)

cout

else

cout

cin.ignore(2);

return 0;

}

Once again this is the code I have so far. What I want it to do is test each word the user inputs not the whole line!!! Here are some sample outputs!!

Please use the code above including queues and stacks to get these outputs!

image text in transcribed

image text in transcribed

image text in transcribed

PA203-01 Programming Exercises PE21DebuglPE2.exe Enter a line and I will see if it's a word-level palindrome Able was I ere I saw Elba That is not a word-level palindrome

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago