// The Stack is used in the program. So it is included here #include #include #include using namespace std; #ifndef STACK_H #define STACK_H template class Stack { public: Stack(); bool empty() const; T peek() const; void push(T value); T pop(); int getSize() const; private: vector elements; }; template Stack::Stack() { } template bool Stack::empty() const { return elements.size() == 0; } template T Stack::peek() const { return elements[elements.size() - 1]; } template void Stack::push(T value) { elements.push_back(value); } template T Stack::pop() { T temp = elements[elements.size() - 1]; elements.pop_back(); return temp; } template int Stack::getSize() const { return elements.size(); } #endif #include #include using namespace std; // Split an expression into numbers, operators, and parenthese vector split(const string& expression); // Evaluate an expression and return the result int evaluateExpression(const string& expression); // Perform an operation void processAnOperator( Stack& operandStack, Stack& operatorStack); int main() { string expression; cout << "Enter an expression: "; getline(cin, expression); cout << expression << " = " << evaluateExpression(expression) << endl; return 0; } vector split(const string& expression) { vector v; // A vector to store split items as strings string numberString; // A numeric string for (unsigned int i = 0; i < expression.length(); i++) { if (isdigit(expression[i])) numberString.append(1, expression[i]); // Append a digit else { if (numberString.size() > 0) { v.push_back(numberString); // Store the numeric string numberString.erase(); // Empty the numeric string } if (!isspace(expression[i])) { string s; s.append(1, expression[i]); v.push_back(s); // Store an operator and parenthesis } } } // Store the last numeric string if (numberString.size() > 0) v.push_back(numberString); return v; } // Evaluate an expression int evaluateExpression(const string& expression) { // Write your code here } // Process one opeator: Take an operator from operatorStack and // apply it on the operands in the operandStack void processAnOperator( Stack& operandStack, Stack& operatorStack) { // Write your code here }