1. postfix and prefix

Hello all wise gurus here at cprogamming dot com. I was in class today and we talked about conversion of something like this
a*(b+c)+d to something like this abc+*d+. okay this made sense when we discussed it but when I actually tried it in a program I get compiler errors up the wazoo. Is there a library that has to be included with this or is this stuff a bunch of hoo haa. Perhaps somebody in here can explain too me or show me an example of this in a practical looking simple program

2. perhaps you could try it yourself and show us some code, or perhaps you could search these boards........or, perhaps you could search google. Perhaps, that is.

3. You will need an algorithm, and the algorithm may need to use a stack. You could use the one from standard template library
Code:
```#include <stack>
using namespace std;

int main() {
stack<int> myStack;

// read the operand and operator one by one
// and print, push, or pop according to the algorithm

return 0;
}```

4. Was the topic of discussion 'prefix & postfix' ?

Because, AFAIK prefix and postfix only apply to the ++ and -- operators (increment & decrement).

These are the unary math operators, as they operate on only one variable.

And this: abc+*d+ is going to give you errors for at least 3 reasons:
- It's looking for a variable named abc.
- You can't have +* without a variable in between.
- d+ doesn't mean anything.

5. Originally Posted by DougDbug
Because, AFAIK prefix and postfix only apply to the ++ and -- operators (increment & decrement).

....
The OP was, I believe, talking about different ways you can write/read mathematical expression.
- read a and push to stack
- read b and push to stack
- read c and push to stack
- read +, pop two operands (b & c) and apply the operation, push the result (x) to stack
- read *, pop two operands (x & a) and apply the operation, push the result (y) to stack
- read d and push to stack
- read -, pop two operands (y & d) and apply the operation, push the result (FINAL RESULT) to stack, and pop it

6. alphaoide you da bomb

alphaoide you da bomb I think that is exactly whut dude was asking for I did manage to do some raw dogg data manipulation check it out.
Code:
```#include<iostream>
using namespace std;
template <class T, int n>
class stack
{
private: T elt[n];
int counter;
public:
void clearstack()
{
counter=-1;
}
bool emptystack()
{
return counter==-1?true:false;
}
bool fullstack()
{
return counter==n - 1?true:false;
}
void push(T x)
{
counter++;
elt[counter]=x;
}
T pop()
{
T x;
x=elt[counter];
counter--;
return x;
}

};
void main()
{
stack<float, 4> s;
stack<float, 4> t;
s.clearstack();
while(! s.fullstack() )
{
float data;
cout<<"Enter an integer data: ";
cin >>data;
s.push(data);
}
int a,b,c,d;
d=s.pop();
cout<<d<<endl;
c=s.pop();
cout<<c<<endl;
b=s.pop();
cout<<b<<endl;
b= b + c;
a=s.pop();
a=a*b;
a=a+d;
s.push(a);
cout << "The total is: " << a << endl;
}```
so that was the plug and punch method. Any suggestions

7. Hello all wise gurus here at cprogamming dot com. I was in class today and we talked about conversion of something like this
a*(b+c)+d to something like this abc+*d+. okay this made sense when we discussed it but when I actually tried it in a program I get compiler errors up the wazoo. Is there a library that has to be included with this or is this stuff a bunch of hoo haa. Perhaps somebody in here can explain too me or show me an example of this in a practical looking simple program
Maybe, depends on how the prefix, postfix is done. One way is to write a small grammar for the infix expression with attributes pre and post denoting the prefix and postfix string, respectively. This method is more work than necessary, but is he most straightward way if you are famaliar with it.

8. >> so that was the plug and punch method. Any suggestions
Well your program only solves one problem: given a, b, c, and d, what is abc+*d+ ??
You should make your program do something like this:
For any given postfix expression,
1. when you see an operand, push
2. when you see an operator, pop two operands and apply the operation, push the result
3. when there's only one element in the stack, that is the final result

I believe that will solve any postfix expression

9. Originally Posted by drdodirty2002
template <class T, int n>
class stack
This is forbidden in C++
Use the built-in std::stack located in the header <stack>.