算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果基本要求:\x05(1)从键盘输入要求解的算术表达式;\x05(2)采用栈结构进行算术表达式的求解过程;\x05(3)能够判断算术表达式

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/15 14:28:31
算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果基本要求:\x05(1)从键盘输入要求解的算术表达式;\x05(2)采用栈结构进行算术表达式的求解过程;\x05(3)能够判断算术表达式

算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果基本要求:\x05(1)从键盘输入要求解的算术表达式;\x05(2)采用栈结构进行算术表达式的求解过程;\x05(3)能够判断算术表达式
算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果
基本要求:
\x05(1)从键盘输入要求解的算术表达式;
\x05(2)采用栈结构进行算术表达式的求解过程;
\x05(3)能够判断算术表达式正确与否;
\x05(4)对于错误表达式给出提示;
\x05(5)对于正确的表达式给出最后的结果;

算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果基本要求:\x05(1)从键盘输入要求解的算术表达式;\x05(2)采用栈结构进行算术表达式的求解过程;\x05(3)能够判断算术表达式
ComlexCalcOperator.h
#ifndef __COMPLEXCALCOPERATOR_H_
#define __COMPLEXCALCOPERATOR_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class ComplexCalcOperator
{
public:
\x05ComplexCalcOperator();
\x05~ComplexCalcOperator();
\x05int Calc(
\x05\x05char *lpszStr,
\x05\x05const int iStrLen,
\x05\x05float* fCalcResult );
\x05
private:
\x05inline bool IsOperator( const char chCur ){
\x05\x05switch( chCur )
\x05\x05{
\x05\x05case '+':
\x05\x05case '-':
\x05\x05case '*':
\x05\x05case '/':
\x05\x05case '(':
\x05\x05case ')':
\x05\x05case '=':
\x05\x05\x05return true;
\x05\x05default:
\x05\x05\x05return false;
\x05\x05}
\x05}
\x05
\x05inline bool IsNumberStart( const char* chCur ){
\x05\x05int length = strlen( chCur );
\x05\x05if (( *chCur >= '0') && ( *chCur 1 ){
\x05\x05\x05\x05switch( *( chCur + 1 ))
\x05\x05\x05\x05{
\x05\x05\x05\x05case '+':
\x05\x05\x05\x05case '-':
\x05\x05\x05\x05case '*':
\x05\x05\x05\x05case '/':
\x05\x05\x05\x05case '(':
\x05\x05\x05\x05case ')':
\x05\x05\x05\x05case '=':
\x05\x05\x05\x05case '#':
\x05\x05\x05\x05\x05return true;
\x05\x05\x05\x05case '.':
\x05\x05\x05\x05\x05if ( length > 2 ){
\x05\x05\x05\x05\x05\x05if (('0' = *( chCur + 2 )))
\x05\x05\x05\x05\x05\x05\x05return true;
\x05\x05\x05\x05\x05}
\x05\x05\x05\x05\x05break;
\x05\x05\x05\x05default:
\x05\x05\x05\x05\x05if ( '0' != *chCur ){
\x05\x05\x05\x05\x05\x05if (('0' = *( chCur + 1 )))
\x05\x05\x05\x05\x05\x05return true;
\x05\x05\x05\x05\x05}
\x05\x05\x05\x05\x05else
\x05\x05\x05\x05\x05\x05if ( IsOperator( *( chCur + 1)) || ( '#' == *( chCur + 1 )))
\x05\x05\x05\x05\x05\x05\x05return true;
\x05\x05\x05\x05}
\x05\x05\x05}
\x05\x05}
\x05\x05
\x05\x05return false;
\x05}
\x05
\x05bool Calc( const float fLeft,
\x05\x05const float fRight,
\x05\x05const char chOp,
\x05\x05float& fResult );
};
#endif
ComplexCalcOperator.cpp
#include "stdafx.h"
#include
#include
#include "ComplexCalcOperator.h"
#define FLOAT_EQ( x,v ) (((( v ) - FLT_EPSILON ) < (x)) && ((x)