资源描述:
《算术表达式求值实习报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、算术表达式求值实习报告TheinformationthatisworthhavingItcomesfromthegenerallearningaccumulationsummaryTheremustbeaproblemPleasebecritical!ArithmeticexpressionsevaluatetheinternshipreportClassno.09040502:052415zhubokaiOne,requirementsanalysis(1)theprogramneedsuserstoinputexpression(operatorcanbeaplus(+),minus(
2、-),multiply(*),inadditionto(/),power():theparentheses(()))ThenumbercanbeanintegerorafloatPressentertofinish!(2)programfunction:computationofarithmeticexpressionsTheoutputAndoutputitspostfixexpression!(3)testdata:8;1+2+3+4;88-1*3;1024/8*16;1024/(8*16);(22+3)*(8/2);The3-3-3;8/(9-9);2times5plus3times
3、2plus4times3plus6.Second,profiledesignToimplementtheaboveprogramfunctionsTheNumbersandoperatorsintheexpressionshouldbestoredseparatelyfromthestackoftwoleadingnodesTheabstractdatatypedefinitionofthestackADTStack{Thedataobject:〃d二{ai
4、ai,〃the〃I二1,2,3,〃・・・nNp0}Datarelations:r={ai-1,ai,)>
5、ai-1,aiunitd,
6、1=2,3,…N}ContractalisthebottomofthestackTheanisthetopBasicoperation:(1)InitStack(&S)Operationresult:constructanemptystackS(2)DestroyStack(&S)Initialconditions:stackSalreadyexistsOperationresult:destroystackS(3)ClearStack(&S)Initialconditions:stackSalreadyexistsTheresult:emptythestackasanemptystack
7、(4)StackEmpty(&S)Initialconditions:stackSalreadyexistsOperationresult:ifstackSisemptystackItreturnsTRUE,Otherwise,FALSE(1)StackLength(&S)Initialconditions:stackSalreadyexistsOperationresult:returnthelengthofthestack(ordepth)(2)GetTop(S&e)Initialconditions:stackSisalreadypresentandnotemptyOperation
8、result:thestacktopelementofSreturnedwithe(3)Push(&S,e)Initialconditions:stackSalreadyexistsOperationresult:insertnewelementeatthetopofthestack(4)Pop(&S,&e)Initialconditions:stackSisalreadypresentandnotemptyOperationresult:thestacktopelementofthestackSisremovedAndr11returnitwithe(1)StackTraverse(SV
9、isit())Initialconditions:stackSalreadyexistsOperationresult:traversingtheaccessstackAcalltoeachelementofS}ADTStackTheprogramconsistsofsixmodules1)mainprogrammodule:Theinitializationofthestack:initializetwostackss