Question
ArrayStack problem in C++ Arithmetic.cpp #include #include #include ArrayStack.h float eval(std::string); // The following main function should not be modified int main(void) { std::string expression
ArrayStack problem in C++
Arithmetic.cpp
#include #include #include \"ArrayStack.h\" float eval(std::string); // The following main function should not be modified int main(void) { std::string expression = \"Continue\"; do { std::cout getline(std::cin, expression); if (expression[0] != 'q') { float result = eval(expression); std::cout } } while (expression[0] != 'q'); return 0; } float eval(std::string expr) { // To be implemented // Any number of support functions may also be added std::cout return 0; }
ArrayStack.cpp
#include #include \"ArrayStack.h\" template ArrayStack::ArrayStack() : top(-1) { // top = -1; } //ArrayStack::ArrayStack(const ArrayStack& orig) { //} // //ArrayStack::~ArrayStack() { //} template bool ArrayStack::isEmpty() const { return (top } template T ArrayStack::peek() const { //If isEmpty(), what do I return? //use precondition, if it fails program halts assert(!isEmpty()); return items[top]; } template bool ArrayStack::pop() { bool result = false; if (!isEmpty()) { top--; result = true; } return result; } template bool ArrayStack::push(const T& newItem) { bool result = false; if (top top++; items[top] = newItem; result = true; } return result; }
ArrayStack.h
#ifndef ARRAYSTACK_H #define ARRAYSTACK_H #include \"StackADT.h\" const int SIZE = 50; template class ArrayStack : StackADT { public: ArrayStack(); // ArrayStack(const ArrayStack& orig); // virtual ~ArrayStack(); //interface methods bool isEmpty() const; bool push(const T& newItem); bool pop(); T peek() const; private: // static const int SIZE = 50; T items[SIZE]; int top; }; #include \"ArrayStack.cpp\" #endif /* ARRAYSTACK_H */
StackADT.h
#ifndef STACKADT_H #define STACKADT_H template class StackADT { public: virtual bool isEmpty() const = 0; virtual bool push(const T& newItem) = 0; virtual bool pop() = 0; virtual T peek() const = 0; }; #endif /* STACKADT_H */
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started