使⽤C++语⾔,设计开发⼀个算术计算器,能够根据⽤户输⼊计算输出表达式结果。

⼀、考核内容
使⽤C++语⾔,设计开发⼀个算术计算器,能够根据⽤户输⼊计算输出表达式结果。
⼆、基本要求

  1. 能够⽀持四则运算功能,如输⼊;
    6 / 3 * 5 + 2.4 - 1 = (输出结果为11.4)
    2 * ( - 3 ) = (输出结果为-6)
  2. 能够⽀持带括号的优先级运算,如;
    6 / 3 * ( 5 + 2.4 - 1 ) = (输出结果为 12.8)
  3. 能够⽀持常⽤数学函数表达式(开⽅、幂、三⻆函数、对数等);
    sqrt ( 4 ) * 5 = (输出结果为10)
  4. ⽀持百分号运算,如:
    100 * 5 % = (输出结果为5)
    100 + ( 100 * 5 % ) = (输出结果为105)
    10 - ( 10 * 20 % ) = (输出结果为8)
    ( 30 / 60 ) % = (输出结果为50)
  5. 对运算结果按指定格式显示,如:
    能够根据设定参数对运算结果的⼩数部分进⾏位数截取或四舍五⼊

/**********************************

  • 算数计算器 vCPP.A.0.S3
    **********************************/
    #include
    #include
    #include
    #include
    #include
    #include
    #include

using namespace std;

typedef vector V1;
typedef stack S1;
typedef stack S2;

//表达式求值类
class EXP {
public:
EXP() {

}

public:
//传入表达式,求值成功返回true,否则返回false,可通过error获取错误原因
bool ____1(const string& _a, double& _b) {
V1 aa;
V1 bb;
if (!____10(____18(a), aa, b)) return false;
if (!___11(aa, bb, b)) return false;
___15(bb, a);
if (!____12(bb, b, b)) return false;
return true;
}

//获取表达式转换的后缀表达式文本串
const string& ____2() const {
    return a_;
}

//获取求值错误原因
const string& ____3() const {
    return b_;
}

private:
//判断token是否是操作符
static bool ____4(const string& _a) {
if (_a == “+”) return true;
if (_a == “-”) return true;
if (_a == “*”) return true;
if (_a == “/”) return true;
if (_a == “^”) return true;
if (_a == “%”) return true;
if (_a == “(”) return true;
if (_a == “)”) return true;
return false;
}

//判断token是否是操作符
static bool ____5(const string& _a) {
    if (_a == "sin") return true;
    if (_a == "cos") return true;
    if (_a == "tan") return true;
    if (_a == "sqrt") return true;
    if (_a == "log") return true;
    if (_a == "ln") return true;
    return false;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dem.o_c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值