Question: Code c++. Fix this function so that is can input sentences like A man, a plan, a canal, Panama! and it ignores spaces, special characters

Code c++.

Fix this function so that is can input sentences like "A man, a plan, a canal, Panama!" and it ignores spaces, special characters and uppercase letters so that it can return that it is a palindrome. Note that to dequeue for queue we need to pass in an item so please do change it so that is calls when its empty like queue.dequeue(). We also need to leave string test because we must pass in a sentence. Please fix so that it runs correctly! Thank you Please use STACK AND QUEUE. I'm posting this question for the second time.

bool palindrome(string test) { char queChar; char stackChar; //char character; StackArr stack(40); QueArr queue(40);

for (int i = 0; i < test.length(); i++) { queue.enque(test[i]); stack.push(test[i]); } for (int i = 0; i < test.length(); i++) { stackChar = stack.topView(); stack.pop(); queue.deque(queChar); //cout << "hi";

if (stackChar != queChar) return false; } // otherwise, they must be a palindrome return true; } int main() {

string test; char choice; do { cout << "Enter a sentence: "; getline(cin, test); cout << "\"" << test << "\""; if (palindrome(test)) cout << " is a palindrome" << endl; else cout << " is NOT a palindrome" << endl; cout << "Do you want to make another check? Y/N :"; cin >> choice; // get input char cin.ignore(); // ignore new lines } while (choice == 'y' || choice == 'Y'); cout << "Thanks!"; return 0; }

Here are the other files I use....

QueArr.h and .cpp

#ifndef _QUEARR_H #define _QUEARR_H #include using namespace std; template < class ItemType > class QueArr { private: int maxSize; int front; int rear; ItemType* items; public: QueArr(); QueArr(int size); void makeEmpty(); bool isEmpty(); bool isFull(); void enque(ItemType item); void deque(ItemType& item); void printQue() const; }; #include "QueArr.cpp" #endif

#ifndef _QUEARR_CPP #define _QUEARR_CPP #include "QueArr.h" template QueArr::QueArr() { maxSize = 10; front = maxSize - 1; rear = maxSize - 1; items = new ItemType[maxSize]; } template QueArr::QueArr(int size) { maxSize = size; front = maxSize - 1; rear = maxSize - 1; items = new ItemType[maxSize]; } template bool QueArr::isEmpty() { return (rear == front); } template bool QueArr::isFull() { return ((rear + 1) % maxSize == front); } template void QueArr::enque(ItemType item) { if (isFull()) return; else { rear = (rear + 1) % maxSize; items[rear] = item; } } template void QueArr::deque(ItemType& item) { if (isEmpty()) return; else { front = (front + 1) % maxSize; item = items[front]; } } template void QueArr::printQue() const { int temp = front; while (temp != rear) { temp = (temp + 1) % maxSize; cout << items[temp] << " "; } cout << endl; } #endif

StackArr.h and .cpp

#ifndef _STACKARR_H #define _STACKARR_H #include using namespace std; template class StackArr { private: int top; int maxStack; ItemType* items; int length; public: StackArr(); StackArr(int max); bool isEmpty(); bool isFull(); void push(ItemType item); void pop(); ItemType topView(); void printStack() const; }; #include "StackArr.cpp" #endif

#ifndef _STACKARR_CPP #define _STACKARR_CPP

#include "StackArr.h"

template StackArr::StackArr() { maxStack = 20; top = -1; items = new ItemType[maxStack]; length = 0; } template StackArr::StackArr(int max) { maxStack = max; top = -1; items = new ItemType[maxStack]; length = 0; } template inline bool StackArr::isEmpty() { return(top == -1); } template inline bool StackArr::isFull() { return (top == (maxStack - 1)); } template void StackArr::push(ItemType item) { if (isFull()) return; else { top++; items[top] = item; length++; } } template void StackArr::pop() { if (isEmpty()) return; else { top--; length--; } } template ItemType StackArr::topView() { if (isEmpty()) { return NULL; } else { return items[top]; } } template void StackArr::printStack() const { if (length == 0) return; else { for (int i = 0; i < length; i++) cout << items[i] << " "; cout << endl; } } #endif

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 Accounting Questions!

Q:

\f