954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

postfix evaluation

im wondering if any1 can send me the function that evaluates the value of a postfix expression in c++<>...
i really need it as soon as possible.. :sad:

AnGeL_69
Newbie Poster
3 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

No, we don't do homework. But if you do the work yourself, we'll be happy to help you along.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

its not a homework actuallly....its a project and its just a small part of it....
i just wanted help in this function only.. :o

AnGeL_69
Newbie Poster
3 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

>its not a homework actuallly....its a project
Okay, that's not different at all.

>i just wanted help in this function only..
No, you wanted a handout. We don't do that, so provide an honest attempt and we'll help.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

loool...
im being honest...anyway,thankx for ur advice... ;)
hope u can help me one day... :o

AnGeL_69
Newbie Poster
3 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

>im being honest
I don't doubt it, but that doesn't change the fact that you're asking for us to do your work for you. Since we have neither the time nor the inclination to write something that we've all probably written before, that's just not going to happen.

>hope u can help me one day...
Hopefully you'll ask for something that I'm willing to help with.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
freaky_ss
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

/* Program to evaluate postfix expression

Author: Javed Khan

Dated: 09-02-2011

*/
#include
#include
#include
#define SIZE 50

int top=-1;
float stack[SIZE/2]={0};

float pop(void);
void push(float num);
int is_alphabet(char symbol);

void main()
{
int i;
char exp[SIZE],ch;
float op1,op2,value[26]={0};
printf("\n\nEnter any correct postfix expression: ");
gets(exp);
for(i=0;exp[i]!='\0';i++)
{
ch=is_alphabet(exp[i]);
if(ch)
value[ch-97]=1;
}
for(i=0;i<26;i++)
{
if(value[i])
{
printf("\nEnter the value of %c: ",97+i);
scanf("%f",&value[i]);
}
}
for(i=0;exp[i]!='\0';i++)
{
ch=is_alphabet(exp[i]);
if(ch)
push(value[ch-97]);
else
{
op2=pop();
op1=pop();
switch (exp[i])
{
case '+':
push(op1+op2);
break;
case '-':
push(op1-op2);
break;
case '*':
push(op1*op2);
break;
case '/':
push(op1/op2);
break;
case '^':
push(pow(op1,op2));
break;
}
}
}
printf("\n\nResult: %0.3f",pop());
}
void push(float num)
{
stack[++top]=num;
}
float pop(void)
{
float num;
num=stack[top];
top--;
return num;
}
int is_alphabet(char ch)
{
if(ch>=97&&ch<=122)
return ch;
else
return 0;
}

khanmj89
Newbie Poster
1 post since Feb 2011
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You