Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

What is the lifetime gift tax applicable exclusion amount?

Answered: 1 week ago