calculating user defined formulas (with c++)

前端 未结 8 1706
萌比男神i
萌比男神i 2020-12-29 12:07

We would like to have user defined formulas in our c++ program. e.g. The value v = x + ( y - (z - 2)) / 2. Later in the program the user would define x,y and z -> t

8条回答
  •  一个人的身影
    2020-12-29 12:25

    Building your own parser for this should be a straight-forward operation:

    ) convert the equation from infix to postfix notation (a typical compsci assignment) (I'd use a stack) ) wait to get the values you want ) pop the stack of infix items, dropping the value for the variable in where needed ) display results

提交回复
热议问题