全文预览

数据结构课程设计--算术表达式求值

上传者:相惜 |  格式:doc  |  页数:16 |  大小:108KB

文档介绍
)Р throw "表达式有错!";Р Р else if(optrTop=='('&&ch==')')Р {Р if(!optr.Pop(optrTop)) throw "表达式有错!";Р Р ch=GetChar();Р Р priorChar=')';Р Р Р }Р Р else if(ch=='('||OperPrior(optrTop)<OperPrior(ch))Р {Р optr.Push(ch);Р priorChar=ch;Р ch=GetChar();Р Р Р }Р Р else Р Р {Р if(!optr.Pop(op)) throw "表达式有错!";Р ElemType left,right;Р Get2Operands(left,right);Р opnd.Push(Operate(left,op,right));Р Р }Р Р Р Р }Р Р if(!optr.Top(optrTop)) throw "表达式有错!";Р Р Р?}Р?if(!opnd.Top(operand)) throw "表达式有错!";Р?Р?cout<<" ";Р?cout<<"运算结果为:";Р?cout<<operand<<endl;Р?Р?Р?Р}Р#endifР主函数功能:Р应用dd.txt建立小小界面;Р针对各种出错情况进行智能处理;Р实现本次计算基本呢操作Р//main主函数Р#include"utility.h"Р#include"calculator.h"Рint main()Р{Р//第一部分进行界面处理,通过文件流的方式Р?char a[100];Р?ifstream in("dd.txt");Р?Р?for(int i=1;i<19;i++)Р?{Р Р in.getline(a,100);Р Р cout<<a<<endl;Р?}

收藏

分享

举报
下载此文档