(c90)(linux)
输入:
sqrt(2-sin(3 * A / B)^ 2.5)+ 0.5 *(C *〜(D)+ 3.11 + B)a b / * a,b,c ,d * / c d输入:
$ b $ (2 * asin(3 * A / B)^ 2.5)+ cos(0.5 *(C *〜(D))+ 3.11 + B) a b / *有一个值为a,b,c,d * / c d输入:
sqrt(2 - sin(3 * A / B)^ 2.5 )/(0.5 *(C *〜(D))+ sin(3.11)+ ln(B)) / * max lenght的公式是250个字符* / a b / * there是a,b,c,d * / c / *的值,每个变量带有一组浮点数* / d正如你可以看到输入中的公式取决于用户。 我的程序将采用公式和n元组值。 然后计算a,b,c和d的每个值的结果。 如果你想我在说,程序的结果是图形。 / 有时候,我想我将输入并存储在字符串。 然后出现另一个想法我应该在结构中存储公式但是不知道如何在结构的基础上构造代码。 /
真的,我不知道如何在程序代码中存储公式,以便我可以做我的工作。 可以显示我吗?
/ * a,b,c,d是字母 cos, sin,sqrt,ln是函数* /解决方案
编写一个词汇分析器来对输入进行标记(将其分解为其组件 - 运算符,标点符号,标识符等)。不可避免地,你会得到一些令牌序列。
之后,有很多方法来评估输入。执行此操作的最简单方法之一是使用分流码算法(后缀表达式的评估易于用资本E)。
(in c90) (linux)
input:
sqrt(2 - sin(3*A/B)^2.5) + 0.5*(C*~(D) + 3.11 +B) a b /*there are values for a,b,c,d */ c dinput:
cos(2 - asin(3*A/B)^2.5) +cos(0.5*(C*~(D)) + 3.11 +B) a b /*there are values for a,b,c,d */ c dinput:
sqrt(2 - sin(3*A/B)^2.5)/(0.5*(C*~(D)) + sin(3.11) +ln(B)) /*max lenght of formula is 250 characters*/ a b /*there are values for a,b,c,d */ c /*each variable with set of floating numbers*/ dAs you can see infix formula in the input depends on user. My program will take a formula and n-tuples value. Then it calculate the results for each value of a,b,c and d. If you wonder I am saying ;outcome of program is graph. /sometimes,I think i will take input and store in string. then another idea is arise " I should store formula in the struct" but ı don't know how I can construct the code on the base of structure./
really, I don't know way how to store the formula in program code so that I can do my job. can you show me?
/* a,b,c,d is letters cos,sin,sqrt,ln is function*/解决方案
You need to write a lexical analyzer to tokenize the input (break it into its component parts--operators, punctuators, identifiers, etc.). Inevitably, you'll end up with some sequence of tokens.
After that, there are a number of ways to evaluate the input. One of the easiest ways to do this is to convert the expression to postfix using the shunting yard algorithm (evaluation of a postfix expression is Easy with a capital E).
更多推荐
解析数学表达式
发布评论