C++. Having difficulty getting the result to return.
The assignment is create a postfix calculator. User will enter a postfix expression and the program will output the result.
Example input and output:
Enter postfix expression: 2 3 4 + * The value of the expression is 14.
Here is the code I have:
stackDriver.cpp
ArrayStack.hpp
StackInterface.hpp
#include
#include #include stack> #include "ArrayStack.hpp" #include "StackInterface.hpD"I using namespace stdi //Function to check postfix expression int checkPostfix(string expression); //Function to check if character is a digit bool digit(char ch) //Function to check if character is operand bool operand(char ch) //Function to evaluate expression and return output int evaluateExpression(char operation, int operand1, int operand2) int main() //Declare string variable string expression; //Get string from user cout Stack; for(int 1-0; i class ArrayStack: public StackInterface private: ItemType items [MAX_STACK]; // Array of stack items int top: /7 Index to top of stack public: ArrayStack); bool isEmpty) const; bool push(const ItemType& newEntry); bool pop); ItemType peek) const; // Default constructor t; // end ArrayStack #include ArrayStack: :ArrayStack) : top (-1) > // end default constructor // Copy constructor and destructor are supplied by the compiler template bool ArrayStack:isEmpty() const return top0; I/ end isEmpty template bool ArrayStackpush (const ItemType& newEntry) bool resultfalse; if (top bool ArrayStackpop() bool result-false; if (!isEmpty ()) topi resulttrue end if return result; > // end pop template ItemType ArrayStack: :peek) const assert(!isEmpty()); I7 Enforce precondition // Stack is not empty; return top return items[top] // end peek // End of implementation file. /Ofile StackInterface.hpp #ifndef STACK-INTERFACE, #define STACK INTERFACE template class StackInterface public: /**Sees whether this stack is empty Oreturn True if the stack is empty, or false if not. / virtual bool isEmpty) const0 /*Adds a new entry to the top of this stack Opost If the operation was successful, newEntry is at the top of the stack. Oparam newEntry The object to be added as a new entry. Oreturn True if the addition is successful or false if not. / virtual bool push (const ItemType& newEntry)-0; /Removes the top of this stack. Opost If the operation was successful, the top of the stack has been removed. Oreturn True if the removal is successful or false if not. * virtual bool pop) 0; /Returns the top of this stack. Opre The stack is not empty. Opost The top of the stack has been returned, and the stack is unchanged. Oreturn The top of the stack./ virtual ItemType peek) const0; /*Destroys object and frees memory allocated by object. virtual ~StackInterface) >; // end StackInterface #endif