算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/14 19:29:18
算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果
基本要求:
\x05(1)从键盘输入要求解的算术表达式;
\x05(2)采用栈结构进行算术表达式的求解过程;
\x05(3)能够判断算术表达式正确与否;
\x05(4)对于错误表达式给出提示;
\x05(5)对于正确的表达式给出最后的结果;
基本要求:
\x05(1)从键盘输入要求解的算术表达式;
\x05(2)采用栈结构进行算术表达式的求解过程;
\x05(3)能够判断算术表达式正确与否;
\x05(4)对于错误表达式给出提示;
\x05(5)对于正确的表达式给出最后的结果;
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)
再问: xiexie,,,,,
再答: 选我为满意答案啊, 如果能赞同下就更好了
#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)
再问: xiexie,,,,,
再答: 选我为满意答案啊, 如果能赞同下就更好了
算术表达式的求解 给定一个算术表达式,通过程序求出最后的结果
给定一个算术表达式,通过程序求出最后的结果.
算术表达式能实现前缀后缀和中缀的表达是求值设计表达式的存储结构能求出结果
编写一个程序,可以计算算术表达式的值,对非法表达式要给出提示,并要求重新输入正确的表达式.(正确的表达式范例:123+4
算术表达式求值设计一个程序,利用栈实现算术表达式的求值要求:(1)以字符串形式输入语法正确算术表达式,参与运算的操作数为
设计一个表达式编写一个程序,并根据其结果说明算术运算、赋值运算、关系运算、逻辑运算之间的优先级别.
编写一个程序,可以计算算术表达式的值,对非法表达式要给出提示,并要求重新输入正确的表达式.
编写一个程序,可以计算算术表达式的值,对非法表达式要给出提示,并要求重新输入正确的表达式
试用C语言设计一个程序,程序的功能是接收任意输入一个算术表达式,判断表达式中的括号是否配对出现.
C有关算术表达式的问题
关于算术表达式的运算疑问,
是关于C语言的一个算术运算符与算术表达式