资源简介
C++算术表达式求值(支持函数)
sin cos tan asin acos atan log sqrt
cos(sin(sqrt(100*sqrt(100*10^2))))*(1.0e+5)/(1.0e-5)
= 8.74513e+009
代码片段和文件信息
#include “stdafx.h“
#include “Arithmetic.h“
#include “deelx.hpp“
CArithmetic::CArithmetic(void)
: result(0) left_result(0)
right_result(0) oper(TEXT(‘\0‘))
left_child(NULL) right_child(NULL)
parent(NULL)
{
}
CArithmetic::CArithmetic(TCHAR choperator const TCHAR *pFuncExp CArithmetic *left CArithmetic *right)
: result(0) left_result(0)
right_result(0) oper(TEXT(‘\0‘))
left_child(NULL) right_child(NULL)
parent(NULL)
{
this->oper = choperator;
funcExp = pFuncExp;
left_child = left;
right_child = right;
}
CArithmetic::CArithmetic(double uresult const TCHAR *pFuncExp)
: result(0) left_result(0)
right_result(0) oper(TEXT(‘\0‘))
left_child(NULL) right_child(NULL)
parent(NULL)
{
this->result = uresult;
funcExp = pFuncExp;
}
CArithmetic::~CArithmetic(void)
{
try
{
if (left_child != NULL)
{
delete left_child;
}
if (right_child != NULL)
{
delete right_child;
}
}
catch (...)
{ }
parent = NULL;
}
double CArithmetic::GetResult()
{
left_result = 0;
right_result = 0;
if (left_child != NULL && right_child != NULL)
{
left_result = left_child->GetResult();
right_result = right_child->GetResult();
switch (oper)
{
case TEXT(‘+‘):
result = left_result + right_result;
break;
case TEXT(‘-‘):
result = left_result - right_result;
break;
case TEXT(‘*‘):
result = left_result * right_result;
break;
case TEXT(‘/‘):
if (right_result != 0)
result = left_result / right_result;
else
result = 0xFFFFFFFF;
break;
case TEXT(‘^‘):
result = pow(left_result right_result);
break;
default:
result = 0;
break;
}
}
basic_string funcExpTmp = funcExp;
Function(funcExpTmp);
return result;
}
void CArithmetic::Output(_ostream_type &os)
{
if (left_child != NULL && right_child != NULL)
{
os << TEXT(‘(‘);
left_child->Output(os);
os << oper;
right_child->Output(os);
os << TEXT(‘)‘);
}
else
{
os << result;
}
}
double CArithmetic::Function( basic_string &funcExp )
{
if (funcExp.empty())
{
return result;
}
if (funcExp.find(TEXT(“sin“)) == 0)
{
result = sin(result);
funcExp = funcExp.substr(3);
}
else if (funcExp.find(TEXT(“cos“)) == 0)
{
result = cos(result);
funcExp = funcExp.substr(3);
}
else if (funcExp.find(TEXT(“tan“)) == 0)
{
result = tan(result);
funcExp = funcExp.substr(3);
}
else if (funcExp.find(TEXT(“asin“)) == 0)
{
result = asin(result);
funcExp = funcExp.substr(4);
}
else if (funcExp.find(TEXT(“acos“)) == 0)
{
result = acos(result);
funcExp = funcExp.substr(4);
}
else if (funcExp.find(TEXT(“atan“)) == 0)
{
result = atan(result);
funcExp = funcExp.substr(4);
}
else if (funcExp.find(TEXT(“log“)) == 0)
{
result = log(result);
funcExp = funcExp.substr(3);
}
else if (funcExp.find(TEXT(“sqrt“)) == 0)
{
resu 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 13162 2014-05-16 17:32 Calculator\Calculator\Arithmetic.cpp
文件 2990 2014-05-16 16:51 Calculator\Calculator\Arithmetic.h
文件 733 2014-05-16 17:36 Calculator\Calculator\Calculator.cpp
文件 4687 2013-11-12 16:20 Calculator\Calculator\Calculator.vcproj
文件 880529 2014-05-16 17:32 Calculator\Calculator\Debug\Arithmetic.obj
文件 6850 2014-05-16 17:36 Calculator\Calculator\Debug\BuildLog.htm
文件 405 2014-05-16 13:00 Calculator\Calculator\Debug\Calculator.exe.em
文件 472 2014-05-16 13:00 Calculator\Calculator\Debug\Calculator.exe.em
文件 387 2014-05-16 17:36 Calculator\Calculator\Debug\Calculator.exe.intermediate.manifest
文件 67466 2014-05-16 17:36 Calculator\Calculator\Debug\Calculator.obj
文件 1048576 2014-05-16 13:00 Calculator\Calculator\Debug\Calculator.pch
文件 65 2014-05-16 17:36 Calculator\Calculator\Debug\mt.dep
文件 10859 2014-05-16 13:00 Calculator\Calculator\Debug\stdafx.obj
文件 527360 2014-05-16 17:36 Calculator\Calculator\Debug\vc80.idb
文件 413696 2014-05-16 17:36 Calculator\Calculator\Debug\vc80.pdb
文件 98132 2012-11-14 17:21 Calculator\Calculator\deelx.hpp
文件 968 2013-11-12 16:19 Calculator\Calculator\ReadMe.txt
文件 215 2013-11-12 16:19 Calculator\Calculator\stdafx.cpp
文件 374 2013-11-12 16:45 Calculator\Calculator\stdafx.h
文件 895 2013-11-12 16:19 Calculator\Calculator.sln
目录 0 2014-05-16 17:36 Calculator\Calculator\Debug
目录 0 2014-05-16 17:36 Calculator\Calculator
目录 0 2014-05-16 16:51 Calculator
----------- --------- ---------- ----- ----
3078821 23
- 上一篇:C++ 超大整数类 及RSA加密
- 下一篇:东南大学c++ PPT
相关资源
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
川公网安备 51152502000135号
评论
共有 条评论