Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想编写一个程序,用特定的值集计算给定的数学函数(由用户)。
要求用户输入一个函数,比如说他输入了f(x)= (x^2)+3x+1然后通过程序我应该显示 [ f(3), f(6) 和 f(9) 的输出) ] 。
具体的问题是如何在类型化函数中获取这些 x,然后如何将函数从字符串转换为双精度或浮点数。
你对此有什么想法吗?
假设我正在使用 C 或 C++
这不是一件容易的事,尤其是在运营商优先于其他人的情况下。
看看其中一些链接,看看你在处理什么:
具有优先级的方程(表达式)解析器?
http://en.wikipedia.org/wiki/Operator-precedence_parser