Can anyone help me fix this program to make sure use stack and use STL library to check the name1 and name2 is palindrome.
Thank you
stackPalindrome.h
#ifndef_STACK_PALINDROME_H
#define_STACK_PALINDROME_H
template <class StackPalindrome>
class StackPalindrome
{
public:
virtual bool isEmpty() const = 0;
virtual bool push(const ItemType& newEntry) =
0;
virtual bool pop() = 0;
virtual ItemType peek() const = 0;
};
#endif
stack.cpp
#include<iostream>
#include<string>
#include<new>
#include "stackPalindrome.h"
using namespace std;
template <class ItemType>
class OurStack
{
private:
stack OurStack;
public:
bool OurStack::isEmpty()
{
return Ourstack.empty();
}
};
bool OurStack::push(const ItemType& newEntry)
{
Ourstack.push(newEntry);
if (Ourstack.top() == newEntry)
return true;
else
return false;
}
bool OurStack::pop()
{
if (!Ourstack.empty())
{
Ourstack.pop();
return true;
}
else
return false;
}
ItemType OurStack::peek()
{
return Ourstack.top();
}
bool isPalindrome(string inp_string)
{
OurStack char_stack;
bool chckStatus = true;
int string_len = (int)inp_string.length();
if (string_len > 0)
{
for (int i = 0; i < string_len;
i++)
char_stack.push(inp_string[i]);
int i = 0;
while (chckStatus &&
!char_stack.isEmpty() && (i < string_len))
{
char item_stack
= char_stack.peek();
char_stack.pop();
if (item_stack
!= inp_string[i])
chckStatus = false;
else
i++;
}
}
else
chckStatus = false;
return chckStatus;
}
int main()
{
string name1 = "love to hoot";
string name2 = "Testing Palindrome ";
if (isPalindrome(name1))
cout << " The string "
<< name1 << "is palindrome.\n"
else
cout << " The string "
<< name1 << "is not palindrome.\n"
if (isPalindrome(name2))
cout << "
The string " << name2 << "is palindrome.\n"
else
cout << "
The string " << name2 << "is not palindrome.\n"
system("pause");
return 0;
}
Below is the C++ code Note that I have done proper indentation but this code is automatically left alligned on this interface
StackPalindrome.h -
#ifndef STACK_PALINDROME_H
#define STACK_PALINDROME_H
#include<bits/stdc++.h>
using namespace std;
template <class ItemType>
class StackPalindrome
{
private:
stack <ItemType>Ourstack;
public:
bool isEmpty();
bool push(const ItemType& newEntry) ;
bool pop() ;
ItemType peek() ;
};
#endif
stack.cpp -
#include<bits/stdc++.h>
#include "stackPalindrome.h"
using namespace std;
template <class ItemType>
bool StackPalindrome<ItemType>::isEmpty()
{
return Ourstack.empty();
}
template <class ItemType>
bool StackPalindrome<ItemType>::push(const ItemType&
newEntry)
{
Ourstack.push(newEntry);
if (Ourstack.top() == newEntry)
return true;
else
return false;
}
template <class ItemType>
bool StackPalindrome<ItemType>::pop()
{
if (!Ourstack.empty())
{
Ourstack.pop();
return true;
}
else
return false;
}
template <class ItemType>
ItemType StackPalindrome<ItemType>::peek()
{
return Ourstack.top();
}
bool isPalindrome(string inp_string)
{
StackPalindrome <char>char_stack;
bool chckStatus = true;
int string_len = (int)inp_string.length();
if (string_len > 0)
{
for (int i = 0; i < string_len; i++)
char_stack.push(inp_string[i]);
int i = 0;
while (chckStatus && !char_stack.isEmpty() && (i
< string_len))
{
char item_stack = char_stack.peek();
char_stack.pop();
if (item_stack != inp_string[i])
chckStatus = false;
else
i++;
}
}
else
chckStatus = false;
return chckStatus;
}
int main()
{
string name1 = "love to hoot";
string name2 = "Testing Palindrome ";
if (isPalindrome(name1))
cout << " The string " << name1 << "is
palindrome.\n";
else
cout << " The string " << name1 << "is not
palindrome.\n";
if (isPalindrome(name2))
cout << " The string " << name2 << "is
palindrome.\n";
else
cout << " The string " << name2 << "is not
palindrome.\n";
system("pause");
return 0;
}
Below is the screenshot of output

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any.
Can anyone help me fix this program to make sure use stack and use STL library...
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...
QUESTION: ADT stack: resizable array-based implementation for Ch4 programming problem 4 "maintain the stacks's top entry at the end of the array" at array index N-1 where the array is currently allocated to hold up to N entries. MAKE SURE YOU IMPLEMENT the functions: bool isEmpty() const; bool push(const ItemType& newEntry); bool pop(); in ArrayStackP4.cpp //FILE StackInterface.h #ifndef STACK_INTERFACE_ #define STACK_INTERFACE_ template<class ItemType> class StackInterface { public: /** Sees whether this stack is empty. @return True if the...
I have a queue and stack class program that deals with a palindrome, I need someone to help to put in templates then rerun the code. I'd greatly appreciate it. It's in C++. Here is my program: #include<iostream> #include<list> #include<iterator> #include<string> using namespace std; class Queue { public: list <char> queue; Queue() { list <char> queue; } void Push(char item) { queue.push_back(item); } char pop() { char first = queue.front(); queue.pop_front(); return first; } bool is_empty() { if(queue.empty()) { return...
#include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0; i<expr.length(); i++){ //Insert code here to push each character onto the stack } cout << "My stack is popped in this order" << endl; while(!myStack.empty()){ //Insert code here to cout the top of the stack one by one //Pop each one after it’s printed out } cout << endl; } void printFromQueue(string expr){ queue<char> myQueue; //Insert code here to push each character onto the...
- 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 {...
stack.h template class Stack{ public: Stack(int max = 10); ~Stack() {delete [] stack;} bool isEmpty() const { return top == -1; } bool isFull() const { return top == MaxStackSize; } T peek() const; void push(const T& x); void pop(); private: int top; int MaxTop; T * stack; } source.cpp What is printed by the following program segment? Stack s; int n; s.push(4); s.push(6); s.push(8); while(!s.isEmpty()) { n = s.peek(); cout << n << ‘ ‘; s.pop(); } cout<< endl;...
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...
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...
can someone please fix this error in the stack file at line 18 ( class Stack2:public Stack { ) this is thew error ----> expected class name before '{' token Queue.h --> #include "Stack.hpp" template <typename ITEM> class Queue { private: ITEM item; Stack <ITEM> * s1= new Stack<ITEM>; Stack <ITEM> * s2= new Stack<ITEM>; public: Queue(){}; bool enqueue (ITEM item); bool dequeue (ITEM &item); bool check = true; ~Queue(); }; //this is the class which contains the functions of...
template <class T> class Stack { public: /** clear * Method to clear out or empty any items on stack, * put stack back to empty state. * Postcondition: Stack is empty. */ virtual void clear() = 0; /** isEmpty * Function to determine whether the stack is empty. Needed * because it is undefined to pop from empty stack. This * function will not change the state of the stack (const). * * @returns bool true if stack is...