第8章计算机学科基础_第1页
第8章计算机学科基础_第2页
第8章计算机学科基础_第3页
第8章计算机学科基础_第4页
第8章计算机学科基础_第5页
已阅读5页,还剩56页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Chapter8,High-LevelProgrammingLanguages高级程序设计语言,8-2,ChapterGoals本章目标,Describethetranslationprocessanddistinguishbetweenassembly,compilation,interpretation,andexecution描述翻译过程,区别汇编、编译、解释和执行。Namefourdistinctprogrammingparadigmsandnamealanguagecharacteristicofeach列出四种不同的程序设计范型,并说明每种的语言特征。Describethefollowingconstructs:streaminputandoutput,selection,looping,andsubprograms描述下列结构:流输入和输出、选择、循环和子程序。,8-3,ChapterGoals,ConstructBooleanexpressionsanddescribehowtheyareusedtoaltertheflowofcontrolofanalgorithm构造Boolean表达式,并说明如何用它们改变算法的控制流Definetheconceptsofadatatypeandstrongtyping定义数据类型和强类型化Explaintheconceptofaparameteranddistinguishbetweenvalueandreferenceparameters解释参数的概念,区别值参和引用参数Describetwocompositedata-structuringmechanisms描述两种复合数据结构机制Name,describe,andgiveexamplesofthethreeessentialingredientsofanobject-orientedlanguage列出并描述面向对象语言的三要素,给出每种要素的实例,8-4,Compilers编译器,CompilerAprogramthattranslatesahigh-levellanguageprogramintomachinecode把用高级语言编写的程序翻译成机器码的程序。High-levellanguagesprovidearichersetofinstructionsthatmakestheprogrammerslifeeveneasier高级程序设计语言提供的指令集要丰富得多,大大简化了程序员的工作。,8-5,Compilers编译器,Figure8.1Compilationprocess,8-6,Interpreters解释器,InterpreterAtranslatingprogramthattranslatesandexecutesthestatementsinsequence解释器是一种翻译程序,用于解释和执行语句序列。Unlikeanassemblerorcompilerwhichproducemachinecodeasoutput,whichisthenexecutedinaseparatestep不像汇编器和编译器只输出需在其他步骤中运行机器码Aninterpretertranslatesastatementandthenimmediatelyexecutesthestatement解释器在翻译过语句之后会立即执行这个语句。Interpreterscanbeviewedassimulators解释器可以看成是模拟器。,8-7,Java,Introducedin1996andsweptthecomputingcommunitybystormPortabilitywasofprimaryimportanceJavaiscompiledintoastandardmachinelanguagecalledBytecode字节码AsoftwareinterpretercalledtheJVM(JavaVirtualMachineJava虚拟机)takestheBytecodeprogramandexecutesit,8-8,ProgrammingLanguageParadigms程序设计语言的范型,Whatisaparadigm?Asetofassumptions,concepts,values,andpracticesthatconstituteawayofviewingreality一组假设、概念、数值和规则,构成了观察现实的方式。,8-9,ProgrammingLanguageParadigms,Figure8.2PortabilityprovidedbystandardizedlanguagesversusinterpretationbyBytecode,8-10,ProgrammingLanguageParadigms,Figure8.2PortabilityprovidedbystandardizedlanguagesversusinterpretationbyBytecode,8-11,ProgrammingLanguageParadigms,Imperativeorproceduralmodel命令模型或过程模型FORTRAN,COBOL,BASIC,C,Pascal,Ada,andC+Functionalmodel函数模型LISP,Scheme(aderivativeofLISP),andML,命令式编程:命令“机器”如何去做事情(how),这样不管你想要的是什么(what),它都会按照你的命令实现。声明式编程:告诉“机器”你想要的是什么(what),让机器想出如何去做(how)。,函数式(functional)语言采用一种基于函数的递归定义的计算模型。他们的灵感来自于lambda演算。本质上,程序被看作是一种从输入到输出的函数,基于一些更简单的函数,通过一种逐步精化的过程定义。,8-12,ProgrammingLanguageParadigms,Logicprogramming逻辑程序设计PROLOGObject-orientedparadigm面向对象范型SIMULAandSmalltalkC+isasanimperativelanguagewithsomeobject-orientedfeaturesJavaisanobject-orientedlanguagewithsomeimperativefeatures,逻辑式(Logic)或基于约束的(constrained-based)语言有命题逻辑得到灵感,他们把计算看作是一种目标制导的搜索过程,设法根据一集逻辑规则找出满足某些特定关系的值。,8-13,FunctionalityofImperativeLanguages命令式语言的功能性,Sequence顺序ExecutingstatementsinsequenceuntilaninstructionisencounteredthatchangesthissequencingSelection选择DecidingwhichactiontotakeIteration迭代(looping循环)RepeatinganactionBothselectionanditerationrequiretheuseofaBooleanexpression,8-14,BooleanExpressionsBoolean表达式,BooleanexpressionAsequenceofidentifiers,separatedbycompatibleoperators,thatevaluatestotrueorfalse一个标识符序列,标示符之间由相容的运算符分隔,求得的值是true或falseBooleanexpressioncanbeABooleanvariableAnarithmeticexpressionfollowedbyarelationaloperatorfollowedbyanarithmeticexpressionABooleanexpressionfollowedbyaBooleanoperatorfollowedbyaBooleanexpression,8-15,BooleanExpressionsBoolean表达式,VariableAlocationinmemorythatisreferencedbyanidentifierthatcontainsadatavalue由存放数值的标识符引用的内存单元Thus,aBooleanvariableisalocationinmemorythatcancontaineithertrueorfalse,8-16,BooleanExpressions,ArelationaloperatorbetweentwoarithmeticexpressionsisaskingiftherelationshipexistsbetweenthetwoexpressionsForexample,xValueyValue,Page233,8-17,StrongTyping强类型,StrongtypingTherequirementthatonlyavalueofthepropertypecanbestoredintoavariable只有类型相符的值才能存入变量的要求成为强类型。DatatypeAdescriptionofthesetofvaluesandthebasicsetofoperationsthatcanbeappliedtovaluesofthetype数据类型:一组值以及能够应用于这种类型的值的基本操作集合的说明。,8-18,DataTypes数据类型,Integernumbers整形数Realnumbers实型数Characters字符Booleanvalues布尔值Strings字符串,8-19,Integers,TherangevariesdependinguponhowmanybytesareassignedtorepresentanintegervalueSomehigh-levellanguagesprovideseveralintegertypesofdifferentsizesOperationsthatcanbeappliedtointegersarethestandardarithmeticandrelationaloperations,8-20,Reals,Liketheintegerdatatype,therangevariesdependingonthenumberofbytesassignedtorepresentarealnumberManyhigh-levellanguageshavetwosizesofrealnumbersTheoperationsthatcanbeappliedtorealnumbersarethesameasthosethatcanbeappliedtointegernumbers,8-21,Characters,IttakesonebytetorepresentcharactersintheASCIIcharactersetTwobytestorepresentcharactersintheUnicodecharactersetOurEnglishalphabetisrepresentedinASCII,whichisasubsetofUnicode,8-22,Characters,ApplyingarithmeticoperationstocharactersdoesntmakemuchsenseComparingcharactersdoesmakesense,sotherelationaloperatorscanbeappliedtocharactersThemeaningof“lessthan”and“greaterthan”whenappliedtocharactersis“comesbefore”and“comesafter”inthecharacterset,8-23,Boolean,TheBooleandatatypeconsistsoftwovalues:trueandfalseNotallhigh-levellanguagessupporttheBooleandatatypeIfalanguagedoesnot,thenyoucansimulateBooleanvaluesbysayingthattheBooleanvaluetrueisrepresentedby1andfalseisrepresentedby0,8-24,Strings,AstringisasequenceofcharactersconsideredasonedatavalueForexample:“Thisisastring.”Containing17characters:oneuppercaseletter,12lowercaseletters,threeblanks,andaperiodTheoperationsdefinedonstringsvaryfromlanguagetolanguageTheyincludeconcatenationofstringsandcomparisonofstringsintermsoflexicographicorder,8-25,Declarations声明,DeclarationAstatementthatassociatesanidentifierwithavariable,anaction,orsomeotherentitywithinthelanguagethatcanbegivenanamesothattheprogrammercanrefertothatitembyname把变量、动作或语言中的其他实体与标识符关联起来的语句,使程序员可以通过名字引用这些项目。,Declarations,8-26,8-27,Declarations,Reservedword保留字AwordinalanguagethathasspecialmeaningCase-sensitive大小写敏感Uppercaseandlowercaselettersareconsideredthedifferent,8-28,Assignmentstatement赋值语句,AssignmentstatementAnactionstatement(notadeclaration)thatsaystoevaluatetheexpressionontheright-handsideofthesymbolandstorethatvalueintotheplacenamedontheleft-handsideNamedconstantAlocationinmemory,referencedbyanidentifier,thatcontainsadatavaluethatcannotbechanged,AssignmentStatement,Page238,8-29,8-30,Input/OutputStructures输入/输出结构,InourpseudocodealgorithmswehaveusedtheexpressionsReadandWriteHigh-levellanguagesviewinputdataasastreamofcharactersdividedintolines,8-31,Input/OutputStructures输入/输出结构,Thekeytotheprocessingisinthedatatypethatdetermineshowcharactersaretobeconvertedtoabitpattern(input)andhowabitpatternistobeconvertedtocharacters(output)Wedonotgiveexamplesofinput/outputstatementsbecausethesyntaxisoftenquitecomplexanddifferssowidelyamonghigh-levellanguages,8-32,ControlStructures控制结构,ControlstructureAninstructionthatdeterminestheorderinwhichotherinstructionsinaprogramareexecuted确定程序中的其他指令的执行顺序的指令。Structuredprogramming结构化程序设计Aprogrammingmethodologyinwhicheachlogicalunitofaprogramshouldhavejustoneentryandoneexit程序中的每个逻辑部件都只有一个入口和一个出口。Sequence,selectionstatements,loopingstatements,andsubprogramstatementsarecontrolstructures,8-33,SelectionStatements,TheifstatementallowstheprogramtotestthestateoftheprogramvariablesusingaBooleanexpression,Page243,8-34,SelectionStatements,Figure8.3Flowofcontrolofifstatement,8-35,SelectionStatements,8-36,SelectionStatements,Page245,8-37,caseStatement,Forconvenience,manyhigh-levellanguagesincludeacase(orswitch)statementAllowsustomakemultiple-choicedecisionseasier,providedthechoicesarediscrete,Page246,8-38,LoopingStatements,ThewhilestatementisusedtorepeatacourseofactionLetslookattwodistincttypesofrepetitions,8-39,LoopingStatements,Count-controlledloopsRepeataspecifiednumberoftimesUseofaspecialvariablecalledaloopcontrolvariable,Figure8.4Flowofcontrolofwhilestatement,8-40,LoopingStatements,Count-controlledloops,8-41,LoopingStatements,Event-controlledloopsThenumberofrepetitionsiscontrolledbyaneventthatoccurswithinthebodyoftheloopitself,Page249,8-42,LoopingStatements,Event-controlledloops,Page249,8-43,SubprogramStatements,WecangiveasectionofcodeanameandusethatnameasastatementinanotherpartoftheprogramWhenthenameisencountered,theprocessingintheotherpartoftheprogramhaltswhilethenamedcodeisexecuted,8-44,SubprogramStatements,TherearetimeswhenthecallingunitneedstogiveinformationtothesubprogramtouseinitsprocessingAparameterlistisalistoftheidentifierswithwhichthesubprogramistowork,alongwiththetypesofeachidentifierplacedinparenthesesbesidethesubprogramname,8-45,SubprogramStatements,Figure8.5Subprogramflowofcontrol,8-46,SubprogramStatements,Figure8.5Subprogramflowofcontrol,8-47,SubprogramStatements,ParametersIdentifierslistedinparenthesesbesidethesubprogramdeclaration;sometimestheyarecalledformalparametersArgumentsIdentifierslistedinparenthesesonthesubprogramcall;sometimestheyarecalledactualparameters,8-48,SubprogramStatements,ValueparameterAparameterthatexpectsacopyofitsargumenttobepassedbythecallingunit(putonthemessageboard)ReferenceparameterAparameterthatexpectstheaddressofitsargumenttobepassedbythecallingunit(putonthemessageboard),8-49,SubprogramStatements,Page253,8-50,Recursion,RecursionTheabilityofasubprogramtocallitselfEachrecursivesolutionhasatleasttwocasesBasecaseThecasetowhichwehaveananswerGeneralcaseThecasethatexpressesthesolutionintermsofacalltoitselfwithasmallerversionoftheproblemForexample,thefactorialofanumberisdefinedasthenumbertimestheproductofallthenumbersbetweenitselfand0:N!=N*(N1)!,8-51,AsynchronousProcessing异步处理,AsynchronousprocessingTheconceptthatinputandoutputcanbeaccomplishedthroughwindowsonthescreenClickinghasbecomeamajorformofinputtothecomputerMouseclickingisnotwithinthesequenceoftheprogramAusercanclickamouseatanytimeduringtheexecutionofaprogramThistypeofprocessingiscalledasynchronous,8-52,CompositeDataTypes复合数据类型,Records记录Arecordisanamedheterogeneous异构collectionofitemsinwhichindividualitemsareaccessedbynameTheelementsinthecollectioncanbeofvarioustypes,8-53,CompositeDataTypes复合数据类型,Page258,8-54,CompositeDataTypes复合数据类型,Page259,8-55,Arrays数组,AnarrayisanamedcollectionofhomogeneousitemsinwhichindividualitemsareaccessedbytheirplacewithinthecollectionTheplacewithinthecollectioni

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论