| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 443 人关注过本帖
标题:c++问题,谢谢
只看楼主 加入收藏
danieljune
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-2-3
结帖率:0
收藏
 问题点数:0 回复次数:2 
c++问题,谢谢
不好意思,学了几节课又不知道怎么入手了。。


题目是
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



一开始需要输入文件的位置,然后根据这个地址来读取这个文件。。。用户输入file location(比如c:\Download\abc.txt)后不知道怎么写code来调用了。。。我只会ifstream myfile ("C:\\Users\\Daniel\\Documents\\Visual Studio 2012\\Projects\\Lab2\\Lab2\\input.txt");这种已知地址的调用。。。长长的一串地址不知道怎么用ifstream调用。。。

接下来调用文件中每个数字符号,然后分析计算,我应该能够写出来,就是一开始怎么根据用户输入的地址调用文件不会,有大神帮我一下吗?

谢谢
搜索更多相关主题的帖子: first expression advantage multiple 
2013-02-22 03:07
SwanK
Rank: 1
等 级:新手上路
帖 子:68
专家分:3
注 册:2013-1-18
收藏
得分:0 
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

//声明变量
//声明 输入文件
int main()
.......
inData.open("c:\\abc.txt"); // 可以直接把文件拷贝到你程序所在目录,不然你必须写明盘符和地址。例如 闪存盘,你必须写明e:\\abc.txt.
cin>>......
2013-02-24 16:31
SwanK
Rank: 1
等 级:新手上路
帖 子:68
专家分:3
注 册:2013-1-18
收藏
得分:0 
#include
#include
#include
using namespace std;

//声明变量
//声明 输入文件
int main()
{
.......
inData.open("c:\\abc.txt"); // 可以直接把文件拷贝到你程序所在目录,不然你必须写明盘符和地址。例如 闪存盘,你必须写明e:\\abc.txt.
cin>>......
...
retunr0;

}
2013-02-24 16:33
快速回复:c++问题,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045879 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved