Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My program currently finds a sentence level palindromes, and I want it to find word level palindromes. I want to run this program on each

My program currently finds a sentence level palindromes, and I want it to find word level palindromes. I want to run this program on each word in the string, as opposed to the whole string. If it doesn't fail on any of the words, then you have a word level palindrome. If it fails any of them, it's not a word level palindrome. Please provide output that your code works/compiles and comment it so I can learn.

I need to write a program to tell if a word is a palindrome using stacks and queues. This needs to be able to only detect word level palindromes. It must ignore special charectors in the user input, and treat words as individual for palindrome. Some example would be

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Please enter text to see if its a pallindrome?

user input : Able elba

Program: would say this is not a word level palindrome.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

An example where it would work:

Please enter text to see if its a pallindrome?

user input : Aba daad

Program would say this IS a word level palindrome. because its only looking at individual words to see if they are word level palindromes.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Another example of the program

Enter a line and I will see if it's a palindrome: 

User input: b5a1@14&ab f*89d4d(F

Program would say this IS a word level palindrome. because its only looking at individual words to see if they are word level palindromes and is also ignoring special symbols, numbers and case sensitivity of the letter input .

I have a good portion of my program finished, I am just trying to figure out how to do some final things to it. I want the program to only check for letters a through z and A = Z, treating uppercase and lower case as the same thing. I want it to ignore any other characters and to just realize word level palindromes, not sentence level, so for example a%345b@a c24&c8d)9cc would be a word level palindrome since the program would ignore the numbers and special characters and only look at each word or set of letters as a candidate. Since uppercase and lowercase will be treated the same, something like AbBa baB should also come back as a word level palindrome. I do Not want sentance level palindromes to work, so something like "able was I ere I saw elba" should NOT work because it is a sentancee level palindrome thus should come back as Not a palindrome. Here is the code I have so far. If you could explain the changes you make so I can learn, I would upvote and be very thankful. Thanks for any help.

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 << "Enter a line and I will see if it's a palindrome:" << endl; 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 << "That is a palindrome." << endl; else cout << "That is not a palindrome." << endl; cin.ignore(2); return 0; 

}

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

More Books

Students also viewed these Databases questions

Question

Question Can plan participants borrow from a VEBA?

Answered: 1 week ago

Question

Question What is an educational benefit trust and how is it used?

Answered: 1 week ago

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago