(9+3)*(8-5)/6*(3+8) in rpn expression in c++
CODE:
#include<iostream>
#include<cctype>
#include<string>
#define MAX 20
using namespace std;
char S[MAX],top=-1;
void push(char ch) //stack push
operation
{
top=top+1;
S[top]=ch;
}
char
pop()
//stack pop operation
{
if(top==-1)
return -1;
else
return S[top--];
}
int getWeight(char ch) //method for
getting precedence of operator
{
if(ch=='(')
return 0;
if(ch=='-' || ch=='+')
return 1;
if(ch== '/' || ch== '*')
return 2;
}
int main()
{
string str; //declaring string
for reading infix expression
cout<<"Enter expression: ";
getline(cin,str); //reading
expression from user
cout<<"RPN expression is:"<<endl;
for(int i=0;i<str.length();i++)
{
if(isalnum(str[i]))
//checking the character is alphanumeric or not
push(str[i]); //pushing character to
stack
else if(str[i]=='(') //if character
is left paranthesis pushing character to stack
push(str[i]);
else if(str[i]==')')
{
while((str[i]=pop())!= '(') //poping stack until left paranthesis
encountered
{
cout<<str[i];
//printing popped characters
}
}
else
{
//if top of
the stack is having heigher precendence than present operator
while(getWeight(S[top])>=getWeight(str[i]))
{
cout<<pop(); //popping
elements until top of the stack have lower presendence
}
push(str[i]); //pushing character to
stack
}
}
while(top!=-1) //popping remainging
characters and printing them
{
cout<<pop();
}
}
OUTPUT:

Please help thank you.
9. Show how to use a stack to evaluate the RPN below, the way we did in class. 5 25 327 3 2 actions stack token Answer Value of the RPN
9. Show how to use a stack to evaluate the RPN below, the way we did in class. 5 25 327 3 2 actions stack token Answer Value of the RPN
Simplify each expression. Thanks
4n 6 n-3 2n 7) a+4_6 2a +6 2 8) 9) x+5 x +3 10) 6 r-6 r+ 3
Programming Assignment 2 – RPN Calculator – Infix to Postfix Conversion and The Evaluations of the Postfix Expression. You are to design and implement and algorithm in Java, to input an Infix expression , convert to a postfix expression and finally evaluate the postfix expression… Follow the examples done during class lectures… We are used to infix notation - ”3 + 4” - where the operator is between the operands. There is also prefix notation, where the operand comes before...
Question 39 2.39 Points Which expression is equal to 5+6+7+8+9? 9 Α) Σk Σ kas 9 Θ) Σκ E5 © Σ5k ka5 Ο Σst ka5
1). The result of Java expression 5*7>3*(5+2) && 3*5-4<6 is ____ a. 35>35&&9<6 b. true && false c. false d. False (2). You save text files containing Java language source code using the file extension___ a. .java b. .class c. .txt d. .src (3). Which of the following is not a primitive data type in the Java programming language? a. boolean b. byte c. int d. Point (4). Given the Java statement int[][] vari = new int[5][7]; the value...
Your program must evaluate algebraic expressions over real numbers in Reverse Polish Notation (RPN). + (addition), - (subtraction), * (multiplication) and / (division) should be treated as arithmetic operations. Depending on the selection, numerical values must be entered and displayed in decimal, hexadecimal or binary form. Example: The expression ((3+4) *(7+1.6-12) -5) / (3-8.7)Will be calculated on your RPN calculator as 3 4 + 7 1.6 + 12 - * 5 - 3 8.7 - / Your RPN computer's user...
398753847300 7 8 8 3 7 5 8 9 5 1 8 1 9 1 3 1 1 9 4 5 3 1 1 5 7 9 583211 120011120 222221102020112111212 302012213 993221514200 4 7 5 5 2 9 1 6 7 3 3 8 4 9 2 1 6 3 5 7 9 6 1 4 7 4 632286 646204842 41343282 56565555 33282524983465454919 65556566446655656465 6 5 565656556 28443321146216537572767174791778729ー8363526 64907 8786 8 3. 1 4 3 3 8 5 4 8...
4 machines and 9 jobs Jobj 1 2 3 4 5 6 7 8 9 Pj 4 9 3 3 6 8 8 12 6 Determine a schedule that minimizes the makespan of the following jobs on 3 machines. a) Compute Cmax(LPT) b) Pair the jobs 1-5, 2-6, 4-5, 7-8-9 • What is Cmax? • Is this Cmax(OPT)? Why? c) What is Cmax(LPT)/Cmax(OPT) ?
Compute the sign of the following permutations: (a) (1, 4, 3, 6, 7)(5, 8, 9, 10). (b) σ ∈ Sn, i 7→ n + 1 − i. (c) Show that this initial configuration of the 15 puzzle is not solvable 3 1 15 13 2 8 5 9 12 7 11 4 14 6 10 − (d) Suppose that (i, j) ∈ Sn is a transposition and that i < j. Find an expression (in terms of i and j...
10) (4 points) a) Find the value of the postfix expression: 2 3 8+5 - (6 points) b) Find the value of the prefix expression:15 7 23 +21 1
10) (4 points) a) Find the value of the postfix expression: 2 3 8+5 - (6 points) b) Find the value of the prefix expression:15 7 23 +21 1