![]() |
postfix expression evaluation,,urgent help plsssssssssss
Hi All Experts!
i need some help ,i have written a code but my output is not correct can somebody look into it ... here's the problem statement.. /*REVISED PROGRAMMING ASSIGNMENT #2 program 2: call it 575_prog2.cpp due on thursday september 27, 2007 by class time evaluate a postfix expression containing some one-letter variables a-z (lower case) whose values are given in a data file called: c:\\temp\\575_prog2_data.txt make sure to include this complete path for the data file. there will not be more than 26 different variables (a-z) and there will not be more than 20 postfixes the operators will be: + - * / and ^ all computations are integer computations e.g., 7/2=3 use a stack of integers and the algorithm below to compute the value of the given postfix expressions. scan a postfix expression left to right char by char: if char is operand (i.e., variable ) find its value and push the value on the stack if the value of the variable is not given, report "invalid postfix" and go to the next problem if char is operator + - * / ^ get the top of the stack (say A) and pop the stack. again get the top of the stack (say B) and pop the stack. compute "B operator A" and push the result on stack if there is any stack problem AT ANY TIME "report invalid postfix" and go to the next problem if there is 0 divide problem report "zero divide" and go to the next problem if char is neither variable nor operator report "invalid postfix" and go to the next problem at the end of scanning the postfix, if stack contains exactly one integer return this value as the answer if stack is empty or has more than one integer report invalid postfix and go to the next problem end of algorithm input data format: the first line gives how many variables there are (n) the next n lines are the variables and their values separated by a space. the rest of the lines are the POSTFIX expressions that you need to evaluate. ================ 5 //this is only a sample; your data may be different a 4 d 9 z 17 y 0 x 2 aD+ ad+zy-x/* xz*yd+ad-*+ ab+ ad*yz*+ad*yz*-* adz*+yx/- zy/ adx^+ your output should look like: ============================= a 4 d 9 z 17 y 0 x 2 aD+ invalid postfix ERROR ad+zy-x/* = 104 xz*yd+ad-*+ = -11 ab+ invalid postfix ERROR ad*yz*+ad*yz*-* = 1296 adz*+yx/- = 157 zy/ zero divide ERROR adx^+ = 85 program 575_prog2.cpp written by <your name here> =================================== and this is my code.... Code:
#include <iostream> |
Re: postfix expression evaluation,,urgent help plsssssssssss
By this time you should know how to have the code blocks in the posts and if you don't know read through the thread Before you make a query (Link at top right corner)
|
Re: postfix expression evaluation,,urgent help plsssssssssss
ok i will keep this in mind,,,but pls help me if u can..
|
| All times are GMT +5.5. The time now is 20:09. |