Y********6 发帖数: 28 | 1 马上去找人买100个包子,求哪位大神能赐教帮忙提点一下怎么写下面这个project,谢
谢啦
不好意思,学了几节课又不知道怎么入手了。。想了一周实在不知道怎么写出来,不知
道怎么一个个调取然后分析,感觉很多变量和变化情况,直接写code好像太复杂了
题目是
In reverse Polish notation the operators follow their operands;
To add 3 and 4, one would write "3 4 +" rather than "3 + 4".
If there are multiple operations, the operator is given immediately after
its second operand
The expression written "3 − 4 + 5” would be written "3 4 − 5 +"
in RPN: first subtract 4 from 3, then add 5 to that
An advantage of RPN is that it obviates the need for parentheses that are
required by infix notation.
* Produce a Reverse Polish Notation calculator that operates on input files.
* First, ask the user for the location of an input file. Open this file.
* Read in the input file, and interpret the input data as RPN. Each new line
should be interpreted as its own math problem.
* Display the resulting answers to the screen.
* If a math problem has an error in its syntax, display SYNTAX ERROR for
that line and continue with the next problem.
* Do not support unary operators.
* Add support for the following operators, written exactly as shown: + - * /
% pow
* Math problems are guaranteed to not have more than 5 total operands. As a
result, you do not need to use arrays (which we have not yet covered).
Sample Input:
3 4 5.0 * −
7
4. * 8 30 +
banana
9 10 + 30 -
Sample Output:
-17
7
SYNTAX ERROR
SYNTAX ERROR
-11
At student request, we've added some additional examples:
4. 7 3-+ 2 -3+
900 40.65-20+
45.2 23.999%
Results:
9
879.35
22
谢谢 |
|