#include <iostream>
using namespace std;
#define MAX 100
class posteval
{
private:
char postfix[MAX];
int top,val,stk[MAX];
public:
posteval()
{
top=-1;
val=0;
}
void read();
void push(int);
int pop();
int convert();
int operation(char);
};
void posteval::push(int n)
{
if(top+1==MAX)
{
cout<<“Stack is full\n”;
return;
}
stk[++top]=n;
}
int posteval::pop()
{
if(top!=-1)
{
return stk[top–];
}
}
void posteval::read()
{
cout<<“Enter a postfix expression:”;
cin>>postfix;
}
int posteval::convert()
{
int i=0;
while(postfix[i]!=’\0′)
{
if(postfix[i]>=48 && postfix[i]<=57)
{
push(postfix[i]-‘0’);
}
else
{
int v=operation(postfix[i]);
push(v);
}
i++;
}
return pop();
}
int posteval::operation(char symb)
{
int op2=pop();
int op1=pop();
switch(symb)
{
case ‘+’:
return op1+op2;
case ‘-‘:
return op1-op2;
case ‘*’:
return op1*op2;
case ‘/’:
return op1/op2;
}
}
int main()
{
posteval eval;
eval.read();
int val=eval.convert();
cout<<“The value after evaluation is:”<<val<<endl;
return 0;
}