计算器软件其实有很多种,但是基本上都是模仿计算器,用鼠标点击按键来操作,这次我们反其道而行之,采用类似文本输入的操作方式。功能1.键盘输入算式,回车后计算结果。2.根据当前输入的函数的一部分,自动找到备选函数。这时可以用上/下键选择需要的函数后,按空格键确定输入。在整个过程中一直可以表示函数的帮助信息。我们可以参考帮助信息,选择合适的函数。3.支持三角函数,反三角函数,求和,平均值,乘方,开方,对数,当然还有包含嵌套的四则运算。相关资源下载(包括可执行文件,可直接在WindowsXP,Windows7环境下执行及源代码,工程文件)下载地址:
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /pub/2011/10/30/使用Qt和Interpreter设计模式开发计算器源码/执行画面如下 技术要点:除了操作界面以外,实际我们是要做这样一个解析器,就面临这一个如何描述我们所面的需求的问题。在这里我们使用EBNF的一种形式,它由W3C定义。我们可以在
XML Path Language (XPath) 2.0 (Second Edition)中找到它的细节。一下是我们在计算器中输入的表达式的描述。
- [1]Expr::= AdditiveExpr
-
-
- [2] AdditiveExpr::=MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )*
-
-
-
- [3]MultiplicativeExpr::= UnaryExpr ( ("*" | "/" | "%" ) UnaryExpr)*
-
-
-
- [4]UnaryExpr::=("-" | "+")* PrimaryExpr
-
-
-
- [5]PrimaryExpr::= NumericLiteral | ParenthesizedExpr | FunctionCall
-
-
-
- [6]NumericLiteral::=IntegerLiteral | DecimalLiteral | DoubleLiteral
-
-
-
- [7]ParenthesizedExpr::="(" Expr? ")"
-
-
-
- [8]FunctionCall::=FunctionName "(" (Expr(","Expr)*)? ")"
-
-
-
- [9]IntegerLiteral ::=Digits
-
-
-
- [10]DecimalLiteral ::=("." Digits) | (Digits "." [0-9]*)
-
-
-
- [11]DoubleLiteral::=(("." Digits) | (Digits ("." [0-9]*)?)) [eE] [+-]? Digits
-
-
-
- [12]Digits ::=[0-9]+
-
-
-
- [13] FunctionName=sinr
-
- |sind
-
- |cosr
-
- |sind
-
- |tanr
-
- |tand
-
- |asinr
-
- |asind
-
- |acosr
-
- |acosd
-
- |atanr
-
- |atand
-
- |power
-
- |root