Question: C + + pls; Modify to add operators ^ for exponent and % for modulus. For example, 3 ^ 2 is 9 and 3 %
C pls;
Modify to add operators for exponent and for modulus. For example, is and is The operator has the highest precedence and the operator has the same precedence as the and operators.
When you create a new submission, you'll notice a template code that includes an implementation of the Stack class. Your task is to implement the missing parts indicated by "your code here".
#include
#include
#include
using namespace std;
#ifndef STACKH
#define STACKH
template
class Stack
public:
Stack;
bool empty const;
T peek const;
void pushT value;
T pop;
int getSize const;
private:
vector elements;
;
template
Stack::Stack
template
bool Stack::empty const
return elements.size;
template
T Stack::peek const
return elementselementssize;
template
void Stack::pushT value
elements.pushbackvalue;
template
T Stack::pop
T temp elementselementssize;
elements.popback;
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 splitconst string& expression;
Evaluate an expression and return the result
int evaluateExpressionconst string& expression;
Perform an operation
void processAnOperator
Stack& operandStack, Stack& operatorStack;
int main
string expression;
cout "Enter an expression: ;
getlinecin expression;
cout expression
evaluateExpressionexpression endl;
return ;
vector splitconst string& expression
vector v; A vector to store split items as strings
string numberString; A numeric string
for unsigned int i ; i expression.length; i
if isdigitexpressioni
numberString.append expressioni; Append a digit
else
if numberStringsize
vpushbacknumberString; Store the numeric string
numberString.erase; Empty the numeric string
if isspaceexpressioni
string s;
sappend expressioni;
vpushbacks; Store an operator and parenthesis
Store the last numeric string
if numberStringsize
vpushbacknumberString;
return v;
Evaluate an expression
int evaluateExpressionconst 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
