In c++ I am to create my own implementation of a Stack class and write a program that reads infix arithmetic expressions and converts them to postfix for the compiler to evaluate them. My problem is with precedence. I've gotten 3+5*2/4-1 to convert to 35241/*+- and 3-5/2*4+1 to convert to 35241*/-+ Here's the code:

Code:

```
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
using namespace std;
const int MAX_SIZE=100;
class Stack
{
private:
char array[100];
int top;
public:
Stack(){
top=0;
}
void push(int val);
char pop();
int size();
char topValue();
bool isEmpty();
void print();
};
void Stack::push(int val)
{
if(size()>99)
{
cout << "Stack Overflow" << endl;
}
else
{
array[top]=val;
top++;
}
}
void Stack::print()
{
for(int i=0;i<top;i++)
{
cout << array[i];
}
}
char Stack::pop()
{
if(isEmpty())
{
cout << "Stack Underflow" << endl;
return '0';
}
else
{
top--;
return array[top];
}
}
bool Stack::isEmpty()
{
if(top<=0)
{
return true;
}
else
{
return false;
}
}
int Stack::size()
{
return top;
}
char Stack::topValue()
{
return top;
}
void main()
{
Stack s;
//bool divide=false;
string exp="";
//string punctuate="";
string popped="";
string result;
int value;
cout << "Enter an Expression: ";
cin >> exp;
cout << endl;
for(int i=0;i<exp.length();i++)
{
if(ispunct(exp[i]))
{
if(exp[i]=='*'||exp[i]=='/')
{
s.pop();
popped=exp[i]+popped;
}
if(exp[i]=='+')
{
s.push(exp[i]);
popped=popped+exp[i];
}
if(exp[i]=='-')
{
s.push(exp[i]);
popped=popped+exp[i];
}
}
else
{
result = result+exp[i];
}
}
cout << result+popped << endl;
system("Pause");
}
```