Modify LiveExample 12.12 EvaluateExpression.cpp to add operators ^ for exponent and % for modulus. For example, 3 ^ 2 is 9 and 3 % 2 is 1. The ^ operator has the highest precedence and the % operator has the same precedence as the * and / operators.  For simplicity, assume the expression has at most one ^ operator.  Sample Run: Enter an expression: (5 * 2 ^ 3 + 2 * 3 % 2) * 4 (5 * 2 ^ 3 + 2 * 3 % 2) * 4 = 160   Code posted below, c++ please! #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) {    } // Process one operator: Take an operator from operatorStack and  // apply it on the operands in the operandStack  void processAnOperator(     Stack& operandStack, Stack& operatorStack) {    }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Modify LiveExample 12.12 EvaluateExpression.cpp to add operators
^ for exponent and % for modulus. For example, 3 ^ 2 is 9 and 3 % 2 is 1. The ^ operator has the highest precedence and the % operator has the same precedence as the * and / operators.  For simplicity, assume the expression has at most one ^ operator.  Sample Run: Enter an expression: (5 * 2 ^ 3 + 2 * 3 % 2) * 4 (5 * 2 ^ 3 + 2 * 3 % 2) * 4 = 160
 
Code posted below, c++ please!

#include <vector>
#include <iostream>
#include <cmath>
using namespace std;

#ifndef STACK_H
#define STACK_H

template<typename T>
class Stack
{
public:
    Stack();
    bool empty() const;
    T peek() const;
    void push(T value);
    T pop();
    int getSize() const;

private:
    vector<T> elements;
};

template<typename T>
Stack<T>::Stack()
{
}

template<typename T>
bool Stack<T>::empty() const
{
    return elements.size() == 0;
}

template<typename T>
T Stack<T>::peek() const
{
    return elements[elements.size() - 1];
}

template<typename T>
void Stack<T>::push(T value)
{
    elements.push_back(value);
}

template<typename T>
T Stack<T>::pop()
{
    T temp = elements[elements.size() - 1];
    elements.pop_back();
    return temp;
}

template<typename T>
int Stack<T>::getSize() const
{
    return elements.size();
}

#endif

#include <string>
#include <cctype>

using namespace std;

// Split an expression into numbers, operators, and parenthese
vector<string> split(const string& expression);

// Evaluate an expression and return the result
int evaluateExpression(const string& expression);

// Perform an operation
void processAnOperator(Stack<int>& operandStack, Stack<char>& operatorStack);

int main()
{
    string expression;
    cout << "Enter an expression: ";
    getline(cin, expression);

    cout << expression << " = "
        << evaluateExpression(expression) << endl;

    return 0;
}

vector<string> split(const string& expression)
{
    vector<string> 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)
{
  
}

// Process one operator: Take an operator from operatorStack and 
// apply it on the operands in the operandStack 
void processAnOperator(
    Stack<int>& operandStack, Stack<char>& operatorStack)
{
  
}

 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education