I need help fixing my code.
My output should be the following.
Hello, world! : false
A dog, a panic in a pagoda : true
A dog, a plan, a canal, pagoda : true
Aman, a plan, a canal--Panama! : true
civic : true
If I had a hi-fi : true
Do geese see God? : true
Madam, I’m Adam. : true
Madam, in Eden, I’m Adam. : true
Neil, a trap! Sid is part alien! : true
Never odd or even : true
No devil lived on. : true
No lemons, nomelon : true
racecar : true
RACEcar : true
Rats live on no evil star. : true
Red rum, sir, is murder! : true
Rise to vote, sir. : true
rotator : true
rotor : true
Step on no pets. : true
Was it a cat I saw? : true
Was it a car or a cat I saw? : true
Yawn a more Roman way. : true
Heres my assignment: https://www.dropbox.com/s/mawyte4ivhadipw/CSC260_P5-Palindrone_StacksQueues.pdf?dl=0
CODE
======================
Stack.h
*******************************
#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;
// Stack template
template <class T>
class Stack
{
public:
T *stackArray;
int stackSize;
int top;
//Constructor
Stack(int);
// Copy constructor
Stack(const Stack&);
// Destructor
~Stack();
// Stack operations
void push(T);
T pop();
bool isFull();
bool isEmpty();
};
//***************************************************
// Constructor *
//***************************************************
template <class T>
Stack<T>::Stack(int size)
{
stackArray = new T[size];
stackSize = size;
top = -1;
}
//***************************************************
// Copy constructor *
//***************************************************
template <class T>
Stack<T>::Stack(const Stack &obj)
{
// Create the stack array.
if (obj.stackSize > 0)
stackArray = new T[obj.stackSize];
else
stackArray = NULL;
// Copy the stackSize attribute.
stackSize = obj.stackSize;
// Copy the stack contents.
for (int count = 0; count < stackSize; count++)
stackArray[count] = obj.stackArray[count];
// Set the top of the stack.
top = obj.top;
}
//***************************************************
// Destructor *
//***************************************************
template <class T>
Stack<T>::~Stack()
{
if (stackSize > 0)
delete [] stackArray;
}
//*************************************************************
// Member function push pushes the argument onto *
// the stack. *
//*************************************************************
template <class T>
void Stack<T>::push(T item)
{
if (isFull())
{
cout << "The stack is full.\n";
}
else
{
top++;
stackArray[top] = item;
}
}
//*************************************************************
// Member function pop pops the value at the top *
// of the stack off, and copies it into the variable *
// passed as an argument. *
//*************************************************************
template <class T>
T Stack<T>::pop()
{
if (isEmpty())
{
cout << "The stack is empty.\n";
return '\0';
}
else
{
T item = stackArray[top];
top--;
return item;
}
}
//*************************************************************
// Member function isFull returns true if the stack *
// is full, or false otherwise. *
//*************************************************************
template <class T>
bool Stack<T>::isFull()
{
bool status;
if (top == stackSize - 1)
status = true;
else
status = false;
return status;
}
//*************************************************************
// Member function isEmpty returns true if the stack *
// is empty, or false otherwise. *
//*************************************************************
template <class T>
bool Stack<T>::isEmpty()
{
bool status;
if (top == -1)
status = true;
else
status = false;
return status;
}
#endif
Queue.h
*******************************
#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
using namespace std;
// Queue template
template <class T>
class Queue
{
public:
T *queueArray; // Points to the queue array
int queueSize; // The queue size
int front; // Subscript of the queue front
int rear; // Subscript of the queue rear
int numItems; // Number of items in the queue
// Constructor
Queue(int);
// Copy constructor
Queue(const Queue &);
// Destructor
~Queue();
// Queue operations
void enqueue(T);
T dequeue();
bool isEmpty() const;
bool isFull() const;
void clear();
};
//***************************************************************
// This constructor creates an empty queue of a specified size.
*
//***************************************************************
template <class T>
Queue<T>::Queue(int s)
{
queueArray = new T[s];
queueSize = s;
front = -1;
rear = -1;
numItems = 0;
}
//***************************************************************
// Copy constructor *
//***************************************************************
template <class T>
Queue<T>::Queue(const Queue &obj)
{
// Allocate the queue array.
queueArray = new T[obj.queueSize];
// Copy the other object's attributes.
queueSize = obj.queueSize;
front = obj.front;
rear = obj.rear;
numItems = obj.numItems;
// Copy the other object's queue array.
for (int count = 0; count < obj.queueSize; count++)
queueArray[count] = obj.queueArray[count];
}
//***************************************************************
// Destructor *
//***************************************************************
template <class T>
Queue<T>::~Queue()
{
delete [] queueArray;
}
//***************************************************************
// Function enqueue inserts a value at the rear of the queue.
*
//***************************************************************
template <class T>
void Queue<T>::enqueue(T item)
{
if (isFull())
cout << "The queue is full.\n";
else
{
// Calculate the new rear position
rear = (rear + 1) % queueSize;
// Insert new item
queueArray[rear] = item;
// Update item count
numItems++;
}
}
//***************************************************************
// Function dequeue removes the value at the front of the queue
*
// and copies t into num. *
//***************************************************************
template <class T>
T Queue<T>::dequeue()
{
if (isEmpty()) {
cout << "The queue is empty.\n";
return '\0';
}
else
{
// Move front
front = (front + 1) % queueSize;
// Retrieve the front item
T item = queueArray[front];
// Update item count
numItems--;
return item;
}
}
//***************************************************************
// isEmpty returns true if the queue is empty, otherwise false.
*
//***************************************************************
template <class T>
bool Queue<T>::isEmpty() const
{
bool status;
if (numItems)
status = false;
else
status = true;
return status;
}
//***************************************************************
// isFull returns true if the queue is full, otherwise false.
*
//***************************************************************
template <class T>
bool Queue<T>::isFull() const
{
bool status;
if (numItems < queueSize)
status = false;
else
status = true;
return status;
}
//*****************************************************************
// clear sets the front and rear indices, and sets numItems to 0.
*
//*****************************************************************
template <class T>
void Queue<T>::clear()
{
front = queueSize - 1;
rear = queueSize - 1;
numItems = 0;
}
#endif
Palindrome.h
*******************************
#ifndef _PALINDROME
#define _PALINDROME
// method protocol declaration
int isPalindrome(char *isPl);
#endif
Palindrome.cpp
*******************************
#include "Palindrome.h"
#include "Stack.h"
#include "Queue.h"
// method to check the input is palindrome or not
int isPalindrome(char *isPl)
{
// declare the required variables
int lp = 0;
Stack<char> palstk(100);
Queue<char> palqu(100);
// code to check the palindrome
while( isPl[lp] != '\0' )
{
if(isalpha(isPl[lp]))
{
palstk.push(toupper(isPl[lp]));
palqu.enqueue(toupper(isPl[lp]));
}
lp++;
}
while(!palstk.isEmpty())
{
if(palqu.front==palstk.top)
{
palqu.dequeue();
palstk.pop();
}else
{
return 0;
}
}
return 1;
}
Main.cpp
*******************************
#include "Palindrome.h"
#include <cstdio>
// main method to invoke the functions to test palindrome
int main()
{
//Character array with a set of strings
char *palcheck[] = {
"Hello world", "A dog, a panic in a pagoda",
"A dog, a plan, a canal, pagoda",
"A man, a plan, a canal?? Panama!",
"civic",
"No lemons, no melon",
"racecar",
"RACEcar",
"Rats live on no evil star.",
"Red rum, sir, is murder!",
"Rise to vote, sir.",
"rotator",
};
// loop code to check each string is palindrome or not
for(int lp=0;lp<12;lp++)
{
printf("%s:",palcheck[lp]);
if(isPalindrome(palcheck[lp]))
printf("yes\n");
else
printf("no\n");
}
}
CODE
======================
Stack.h
*******************************
#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;
// Stack template
template <class T>
class Stack
{
public:
T *stackArray;
int stackSize;
int top;
//Constructor
Stack(int);
// Copy constructor
Stack(const Stack&);
// Destructor
~Stack();
// Stack operations
void push(T);
T pop();
bool isFull();
bool isEmpty();
};
//***************************************************
// Constructor *
//***************************************************
template <class T>
Stack<T>::Stack(int size)
{
stackArray = new T[size];
stackSize = size;
top = -1;
}
//***************************************************
// Copy constructor *
//***************************************************
template <class T>
Stack<T>::Stack(const Stack &obj)
{
// Create the stack array.
if (obj.stackSize > 0)
stackArray = new T[obj.stackSize];
else
stackArray = NULL;
// Copy the stackSize attribute.
stackSize = obj.stackSize;
// Copy the stack contents.
for (int count = 0; count < stackSize; count++)
stackArray[count] = obj.stackArray[count];
// Set the top of the stack.
top = obj.top;
}
//***************************************************
// Destructor *
//***************************************************
template <class T>
Stack<T>::~Stack()
{
if (stackSize > 0)
delete [] stackArray;
}
//*************************************************************
// Member function push pushes the argument onto *
// the stack. *
//*************************************************************
template <class T>
void Stack<T>::push(T item)
{
if (isFull())
{
cout << "The stack is full.\n";
}
else
{
top++;
stackArray[top] = item;
}
}
//*************************************************************
// Member function pop pops the value at the top *
// of the stack off, and copies it into the variable *
// passed as an argument. *
//*************************************************************
template <class T>
T Stack<T>::pop()
{
if (isEmpty())
{
cout << "The stack is empty.\n";
return '\0';
}
else
{
T item = stackArray[top];
top--;
return item;
}
}
//*************************************************************
// Member function isFull returns true if the stack *
// is full, or false otherwise. *
//*************************************************************
template <class T>
bool Stack<T>::isFull()
{
bool status;
if (top == stackSize - 1)
status = true;
else
status = false;
return status;
}
//*************************************************************
// Member function isEmpty returns true if the stack *
// is empty, or false otherwise. *
//*************************************************************
template <class T>
bool Stack<T>::isEmpty()
{
bool status;
if (top == -1)
status = true;
else
status = false;
return status;
}
#endif
Queue.h
*******************************
#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
using namespace std;
// Queue template
template <class T>
class Queue
{
public:
T *queueArray; // Points to the queue array
int queueSize; // The queue size
int front; // Subscript of the queue front
int rear; // Subscript of the queue rear
int numItems; // Number of items in the queue
// Constructor
Queue(int);
// Copy constructor
Queue(const Queue &);
// Destructor
~Queue();
// Queue operations
void enqueue(T);
T dequeue();
bool isEmpty() const;
bool isFull() const;
void clear();
};
//***************************************************************
// This constructor creates an empty queue of a specified size.
*
//***************************************************************
template <class T>
Queue<T>::Queue(int s)
{
queueArray = new T[s];
queueSize = s;
front = -1;
rear = -1;
numItems = 0;
}
//***************************************************************
// Copy constructor *
//***************************************************************
template <class T>
Queue<T>::Queue(const Queue &obj)
{
// Allocate the queue array.
queueArray = new T[obj.queueSize];
// Copy the other object's attributes.
queueSize = obj.queueSize;
front = obj.front;
rear = obj.rear;
numItems = obj.numItems;
// Copy the other object's queue array.
for (int count = 0; count < obj.queueSize; count++)
queueArray[count] = obj.queueArray[count];
}
//***************************************************************
// Destructor *
//***************************************************************
template <class T>
Queue<T>::~Queue()
{
delete [] queueArray;
}
//***************************************************************
// Function enqueue inserts a value at the rear of the queue.
*
//***************************************************************
template <class T>
void Queue<T>::enqueue(T item)
{
if (isFull())
cout << "The queue is full.\n";
else
{
// Calculate the new rear position
rear = (rear + 1) % queueSize;
// Insert new item
queueArray[rear] = item;
// Update item count
numItems++;
}
}
//***************************************************************
// Function dequeue removes the value at the front of the queue
*
// and copies t into num. *
//***************************************************************
template <class T>
T Queue<T>::dequeue()
{
if (isEmpty()) {
cout << "The queue is empty.\n";
return '\0';
}
else
{
// Move front
front = (front + 1) % queueSize;
// Retrieve the front item
T item = queueArray[front];
// Update item count
numItems--;
return item;
}
}
//***************************************************************
// isEmpty returns true if the queue is empty, otherwise false.
*
//***************************************************************
template <class T>
bool Queue<T>::isEmpty() const
{
bool status;
if (numItems)
status = false;
else
status = true;
return status;
}
//***************************************************************
// isFull returns true if the queue is full, otherwise false.
*
//***************************************************************
template <class T>
bool Queue<T>::isFull() const
{
bool status;
if (numItems < queueSize)
status = false;
else
status = true;
return status;
}
//*****************************************************************
// clear sets the front and rear indices, and sets numItems to 0.
*
//*****************************************************************
template <class T>
void Queue<T>::clear()
{
front = queueSize - 1;
rear = queueSize - 1;
numItems = 0;
}
#endif
Palindrome.h
*******************************
#ifndef _PALINDROME
#define _PALINDROME
// method protocol declaration
int isPalindrome(char *isPl);
#endif
Palindrome.cpp
*******************************
#include "Palindrome.h"
#include "Stack.h"
#include "Queue.h"
// method to check the input is palindrome or not
int isPalindrome(char *isPl)
{
// declare the required variables
int lp = 0;
Stack<char> palstk(100);
Queue<char> palqu(100);
// code to check the palindrome
while( isPl[lp] != '\0' )
{
if(isalpha(isPl[lp]))
{
palstk.push(toupper(isPl[lp]));
palqu.enqueue(toupper(isPl[lp]));
}
lp++;
}
while(!palstk.isEmpty())
{
if(palqu.dequeue()!=palstk.pop())
{
return 0;
}
}
return 1;
}
Main.cpp
*******************************
#include "Palindrome.h"
#include <cstdio>
// main method to invoke the functions to test palindrome
int main()
{
//Character array with a set of strings
char *palcheck[] = {
"Hello world", "A dog, a panic in a pagoda",
"A dog, a plan, a canal, pagoda",
"A man, a plan, a canal?? Panama!",
"civic",
"No lemons, no melon",
"racecar",
"RACEcar",
"Rats live on no evil star.",
"Red rum, sir, is murder!",
"Rise to vote, sir.",
"rotator",
};
// loop code to check each string is palindrome or not
for(int lp=0;lp<12;lp++)
{
printf("%s:",palcheck[lp]);
if(isPalindrome(palcheck[lp]))
printf("yes\n");
else
printf("no\n");
}
}
==============================
See Output

Thanks, PLEASE RATE if helpful
I need help fixing my code. My output should be the following. Hello, world! : false...
Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ) , brackets [] and curly braces { }. For example, the string {a(b+ac)d[xy]g} and kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match both in number and in the order they occur in the string). Your function must use...
- implement the Stack ADT using array – based approach. Use C++ program language #include "StackArray.h" template <typename DataType> StackArray<DataType>::StackArray(int maxNumber) { } template <typename DataType> StackArray<DataType>::StackArray(const StackArray& other) { } template <typename DataType> StackArray<DataType>& StackArray<DataType>::operator=(const StackArray& other) { } template <typename DataType> StackArray<DataType>::~StackArray() { } template <typename DataType> void StackArray<DataType>::push(const DataType& newDataItem) throw (logic_error) { } template <typename DataType> DataType StackArray<DataType>::pop() throw (logic_error) { } template <typename DataType> void StackArray<DataType>::clear() { } template <typename DataType> bool StackArray<DataType>::isEmpty() const {...
Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...
C++ Please ensure code is fully working, will rate Question to be answered: Repeat Exercise 1 for the class linkedStackType question one: Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same, false otherwise. Also, write the definition...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...
Hello, I have some errors in my C++ code when I try to debug it.
I tried to follow the requirements stated below:
Code:
// Linked.h
#ifndef INTLINKEDQUEUE
#define INTLINKEDQUEUE
#include <iostream>
usingnamespace std;
class IntLinkedQueue
{
private: struct Node {
int data;
Node *next;
};
Node *front; // -> first item
Node *rear; // -> last item
Node *p; // traversal position
Node *pp ; // previous position
int size; // number of elements in the queue
public:
IntLinkedQueue();...
Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...
PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...
Given an array-based stack of integers, sort it largest to smallest using recursion. Do NOT use any loop constructs such as while, for and so on. Only use the following stack ADT functions in the recursion: IsEmpty Push Pop Top (note: doesn’t remove anything from the stack). Your program should read 10 integers into a stack from a file named input.txt (outputting them to the screen first) then implement the recursions. Use stacks only, no queues. The program should then...
My Output s1 (size 0): s1 is empty Testing push() s1 (size 1): 17 s1 is not empty s1 (size 4): 4 6 2 17 s1 is not empty Testing copy constructor s1 (size 4): 4 6 2 17 s2 (size 4): 4 6 2 17 Testing clear() s1 (size 0): s2 (size 4): 0 1477251200 1477251168 1477251136 s3 (size 4): 28 75 41 36 Testing assignment operator s3 (size 4): 28 75 41 36 s4 (size 4): 28 75...