欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOCX文档下载  

    Pascal Tutorial 过程式编程语言.docx

    • 资源ID:7143142       资源大小:260.21KB        全文页数:102页
    • 资源格式: DOCX        下载积分:5金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要5金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Pascal Tutorial 过程式编程语言.docx

    PascalTutorial-IntroIntroductionIFYOUKNOWNOTHINGABOUTPASCA1.AssumingthatyouknownothingatallaboutPascal,andinfact,thatyoumayknownothingaboutprogrammingingeneral,wewillbegintostudyPascal.IfyouarealreadysomewhatfamiliarwithprogrammingandespeciallyPascal,youW川probablywanttoskipveryquicklythroughthefirstfewchapters.Youshouldatleastskimthesechapters,andyoushouldreadtheremainderofthisintroduction.Afewcommentsareinordertogetusstartedintherightdirection.ThesampleprogramsincludedwiththistutorialaredesignedtoteachyouthebasicsofPascalandtheydonotincludeanycleverortrickycode.Nearlyalloftheprogramsarereallyquitedumbasfarasbeingusefulprograms,butallwillteachoneormoreprinciplesofPascal.Ihaveseenonetutorialthatincludeda12pageprogramasthefirstexample.Infacttherewereonly2exampleprogramsintheentiretutorial,anditwasimpossibletogleantheessentialsofprogrammingfromthatsystem.Forthisreason,Iwillcompletelybypassanylongprogramsuntiltheveryendofthistutorial.Inorderto川UStratefundamentalconceptsusedinPascalprogramming,allprogramswillbeveryshortandconciseuntilwereachthelastchapter.1.ARGERPASCA1.PROGRAMSChapter16hassomeratherlargeprogramstoillustratetoyouhowtowritealargeprogram.ItwouldbeadisservicetoyoutoshowyoualloftheconstructsofPascalandnotshowyouhowtoputthemtogetherinameaningfulwaytobuildalargeprogram.AftercompletingallofthefundamentalsofPascal,itwillthenbeveryeasyforyoutousethetoolslearnedtobuildaslargeaprogramasyoudesireorrequireforyournextprogrammingproject.AnotherproblemIhavenoticedinexampleprogramsistheuseofonewordforalldefinitions.Forexample,asortprogramisstoredinafilecalledSORT,theprogramisnamedSort,andvariouspartsoftheprogramarereferredtoasSortl1Sort2,etc.Thiscanbeconfusingsinceyouhavenoideaiftheprogramnamemustbethesameasthefilename,orifanyoftheothernameswerechosentobethesamebecauseofsomeobscurerulenotclearlydocumented.Forthisreason,theexampleprogramsusecompletelyarbitrarynameswheneverthechoiceofanameaddsnothingtothereadabilityorclarityofaprogram.Asan川UStrationofthistthefirstprogramisnamedPuppy_Dog.ThisaddsnothingtotheunderstandingoftheprogrambutdoesillustratethattheprogramnamemeansnothingtothePascalcompilerconcerningwhattheprogramdoes.DuetothefundamentaldesignofthePascallanguage,certainwordsare"reserved"andcanonlybeusedfortheirdefinedpurposes.ThesearelistedinyorTURBOPascalreferencemanual.Allofthesampleprogramsinthistutorialarewrittenwiththereservedwordsinalllower-caseletters,andtheuservariablesinlowercasewiththefirstlettercapitalizedsincethisisbecominganacceptedindustrystandard.Don'tworryaboutwhatreservedwordsareyet,theywillbecompletelydefinedlater.Inthistutorial,allreservedwords,typenames,variablenames,andprocedureandfunctionnameswillbelistedinboldfacetypewithinthetextasanaidtothestudent.whatIsacompiler?TherearetwomethodsusedtorunanycomputerprogramthatiswritteninareadableformofEnglish.Thefirstmethodistouseaninterpreter.Aninterpreterisaprogramthatlooksateachlineofthe"English"program,decideswhatthe"English"onthatlinemeans,anddoeswhatitsaystodo.Ifoneofthelinesisexecutedrepeatedly,itmustbescannedandanalyzedeachtime,greatlyslowingdownthesolutionoftheproblemathand.Acompiler,ontheotherhand,isaprogramthatlooksateach"English"statementonetimeandconvertsitintoacodethatthecomputerunderstandsdirectly.Whenthecompiledprogramisactuallyrun,thecomputerdoesnothavetofigureoutwhateachstatementmeans,itisalreadyinaformthatthecomputercanrundirectly,resultinginmuchfasterexecutionoftheprogram.ThistutorialiswrittenespeciallyforBorlandInternational'sTURBOPascalcompilersversion5.0through7.0.Theseareveryhighqualitycompilersthatcandonearlyanythingyouwillaskthemtodosincetheyaresoflexible.TheoriginalintentofthistutorialwastowriteitinsuchawaythatitwouldbecompletelygenericandusablewithanygoodPascalcompiler.TheprogrammersatBorlandincludedagreatmanynonstandardaidsforthePascallanguageandresultedinaverygoodproductthathasdominatedthemarketformicrocomputers.TocompletelyomitalloftheextensionswoulddothoseofyouwiththeBorlandcompilerarealdisservice,andtoincludetheextensionswouldnotallowothercompilerstobeusedeffectivelywiththistutorial.ThedecisionwasmadetousetheBorlandextensionswhichmaymakethetutorialdifficulttousewithothercompilers.IfyouhaveaneedtousePascalwithsomeothercompiler,TURBOPascalissoinexpensivethatitwouldbeawisedecisiontopurchaseacopysolelyforthepurposeoflearningthePascalprogramminglanguage,thenmovingtotheothercompileronaminicomputeroramainframeusingtheaccumulatedknowledgetoveryquicklylearntheextensionsprovidedbythatparticularcompiler.Atanyrate,thistutorialwillnotteachyoueverythingyouwilleverneedtoknowaboutPascal.Itwill,however,teachyouthefundamentalsandtheadvancedfeaturesofPascal,butofevenmoreimportanceistheknowledgeofPascalterminologyneededtoprogressonyourownintomoreadvancedtopicsofPascalandprogrammingingeneral.Youwillfindthatexperiencewillbeyourbestteacher.WHICHVERSIONOFTURBOPASCA1.?SomeoftheexampleprogramswillnotworkwithsomeoftheearlierversionsofTURBOPascal.Thisisprimarilyduetothefactthatobjectorientedprogrammingcapabilitieswereaddedtoversion5.5,andimprovedoninlaterversions.Mostoftheexampleprogramswillworkwithanyversionhowever.ItshouldbepointedoutthateachsuccessiveversionofTURBOPascalhasbeenanimprovementoverthepreviousversionsinceadditionalcapabilitieshavebeenadded,andeachnewonecompilesalittlefasterandresultsinsmallerbutfasterexecutablecodethanthepreviousversion.AnyoftheversionsofTURBOPascalcanbeusedtolearntoprograminPascal,sowhicheverversionyouhaveonhandwillbeadequate.1.ater,whenyoubecomemoreversedinprogrammingtechniques,youmaywishtoupgradetotheabsolutelatestversion.EAR1.YVERSIONSOFTURBOPASCA1.MostofthefileswillcompileproperlywithTURBOPascalversions2.0through4.0.Nowarningwillbegivenaboutwhichfileswillnotcompilewiththeseversionssincetheyhavebeensupersededforsolong.Ifyouarestillusingoneoftheearlierversions,itwouldbegoodforyoutopurchaseanewerversionbecauseoftheflexibility.WHATABOUTTURBOPASCA1.VERSION5.5&NEWER?Chapters14and15ofthistutorialarewrittenespeciallyforTURBOPascalversion5.5andnewertodiscusstheuseofobjectorientedprogrammingandhowtousetheBorlandextensions.Sincethetopicofobjectorientedprogrammingisaverylargeanddiversefieldofstudyandonlyalimitedspaceisavailabletodiscussitinthistutorial,thesechapterswillgiveyouonlyabriefoverviewofwhatitisandhowtouseit.Youwillfind13completeexampleprogramstogetyoustartedinthisnewandverymeaningfulendeavorandthisintroductionshouldwhetyourappetitetocontinueyourstudyinmoredepth.IfyouareusinganearlyversionofTURBOPascalwithouttheobjectorientedextensions,itwouldpayyoutoupgradesoyoucanlearnhowtousethisnewprogrammingmethod.Objectorientedprogramminghasthepotentialtogreatlyimprovethequalityofyourcodeandtoreducethedebuggingtimerequired.PREPARATIONFORUSEOFTHISTUTORIA1.CopytheexamplefilesintoyourTURBOPascalworkingdirectoryandyouarereadytobegin,providedofcoursethatyouhavealreadylearnedhowtostarttheTURBOsystemandhowtoeditaPascalfile.IfyouarenotusingTURBOPascal,youwillstillbeabletocompileandexecutemanyofthesePascalfiles,sincemostoftheexamplesusestandardPascalsyntax.TherewillbesomestatementsusedwhichareuniquetoTURBOPascalandwillnotworkwithyourcompiler.Thiswillbeespeciallytruewhenyoucometothechapteronstandardinputandoutputsincethisiswheremostcompilersdiffer.Unfortunately,thisisoneofthemostimportantaspectsofanyprogramminglanguage,sinceitisrequiredtogetdataintoandoutofthecomputertodoanythinguseful.Youwillalsofindthatchapter13,coveringthetopicofunits,isuniquetoTURBOPascalandwillnotworkwithanyPascalcompilersotherthanTURBOPascal.WHATABOUTTHEPROGRAMMINGEXERCISES?Itishighlysuggestedthatyoudotheprogrammingexercisesafteryoucompletethestudyforeachchapter.Theyarecarefullyselectedtotestyourunderstandingofthematerialcoveredinthatchapter.Ifyoudonotwrite,enter,debug,andruntheseprograms,youW川OnlybeproficientatreadingPascal.Ifyoudotheexercisescompletely,youwillhaveagoodstartatbeingaPascalprogramwriter.ItshouldalsobementionedthatthistutorialwillnotteachyoueverythingyouwilleverneedtoknowaboutPascal.Youwillcontinuetolearnnewtechniquesaslongasyoucontinuetowriteprograms.Experienceisthebestteacherherejustasitisinanyendeavor.ThistutorialwillteachyouenoughaboutPascalthatyoushouldfeelverycomfortableasyousearchthroughthereferencemanualforsometopic.YouwillalsobeabletoreadandunderstandanyPascalprogramyoufindintextbooksormagazines.AlthoughtheprimarygoalofthistutorialistoteachyouthesyntaxanduseofPascal,themostimportantbyproductistheknowledgeofPascalterminologyyouwillgain.ThisterminologywillenableyoutolearnevenmoreaboutPascalandprogrammingingeneral.THEANSWERSTOPROGRAMMINGEXERCISESThefilepasans.zipcontainsananswertoeachoftheprogrammingexercisesgivenattheendofthechapters.Youshouldattempttodooriginalworkoneachoftheexercisesbeforereferringtotheseanswers,inordertogainyourownprogrammingexperience.Theseanswersaregivenforyourinformationincaseyouarecompletelystuckonhowtosolveaparticularproblem.Theseanswersarenotmeanttobetheonlyanswer,sincetherearemanywaystoprogramanything,buttheyaremeanttoillustrateonewaytosolvethesuggestedprogrammingproblem.TheanswersareallincompilablefilesnamedintheformatCHnn_m.PASwhereisthechapternumber,andmistheexercisenumber.Ifthereismorethanoneanswerrequired,anA,B,orCisincludedfollowingtheexercisenumber.AdVanCetoChaPter1RetUmtotheTableOfContentsCopyright©1986-1997CoronadoEnterprises-1.astupdate,March16,1997GordonDodriH-dodrill-PleaSeemailanycommentsorSIlggeStiOns.PascalTutorial-Chapter1WhatIsAComputerProgram?THISCHAPTERISFORNEWPROGRAMMERSIfyouareacompletenovicetocomputersyouwillfindtheinformationinthischapteruseful.Ifhowever,youhavehadsomeexperiencewithprogramming,youcancompletelyignorethischapter.ItwilldealwithafewfundamentalsofcomputersingeneralandwillintroducenothingthatisspecifictoPascal.WHATISACOMPUTERPROGRAM?Acomputerisnothingbutaverydumbmachinethathastheabilitytoperformmathematicaloperationsveryrapidlyandveryaccurately,butitcandonothingwithouttheaidofaprogramwrittenbyahumanbeing.Moreover,ifthehumanbeingwritesaprogramthatturnsgooddataintogarbage,thecomputerwillveryobediently,andveryrapidly,turnthegooddataintogarbage.Itispossibletowriteacomputerprogramwithonesmallerrorinitthatwilldothatverything,andinsomecasesappeartobegeneratinggooddata.Itisuptothehumanprogrammertodesignaprogramtoachievethedesiredresults.Acomputerprogramissimplya"recipe"whichthecomputerwilluseontheinputdatatoderivethedesiredoutputdata.Itissimilartotherecipeforbakingacake.Theinputdataiscomparabletotheingredients,includingtheheatsuppliedbytheoven.Theprogramiscomparabletotherecipeinstructionstomix,stir,wait,heat,cool,andallotherpossibleoperationsontheingredients.Theoutputofthecomputerprogramcanbecomparedtothefinalcakesittingonthecounterreadytobecutandserved.Acomputerprogramisthereforecomposedoftwoparts,thedatauponwhichtheprogramoperates,andtheprogramthatoperatesonthedata.Thedataandprogramareinseparableasimpliedbythelastsentence.WHATARECONSTANTS?Nearlyanycomputerprogramrequiressomenumbersthatneverchangethroughouttheprogram.Theycanbedefinedonceandusedasoftenasneededduringtheoperationoftheprogram.Toreturntotherecipeanalogy,onceyouhavedefinedhowbigatablespoonis,youcanusethesametablespoonwithoutregardtowhatyouaremeasuringwithit.Whenwritingacomputerprogram,youcandefinethevalueofPl=3.141592,andcontinuetouseitwhereveritmakessenseknowingthatitisavailable,andcorrect.WHATAREVARIAB1.ES?Inadditiontoconstants,nearlyeverycomputerprogramusessomenumbersthatchangeinvaluethroughouttheprogram.Theycanbedefinedasvariables,thenchangedtoanyvaluesthatmakesensetotheproperoperationoftheprogram.Anexamplewouldbethenumberofeggsintheaboverecipe.Ifasinglelayerofcakerequired2eggs,thenatriplelayercakewouldrequire6eggs.Thenumberofeggswouldthereforebeavariable.HOWDOWEDEFINECONSTANTSORVARIAB1.ES?Allconstantsandvariableshaveanameandavalue.Inthelastexample,thenameofthevariablewas"eggs",andthevaluewaseither2or6dependingonwhenwelookedatthestoreddata.Inacomputerprogramtheconstantsandvariablesaregivennamesinmuchthesamemanner,afterwhichtheycanstoreanyvaluewithinthedefinedrange.Anycomputerprogramminglanguagehasameansbywhichconstantsorvariablescanbefirstnamed,thenassignedavalue.ThemeansfordoingthisinPascalwillbegiventhroughouttheremainderofthistutorial.WHATISSOGOODABOUTPASCA1.?Somecomputerlanguagesallowtheprogrammertodefineconstantsandvariablesinaveryhaphazardmannerandthencombinedatainanevenmorehaphazardmanner.Forexample,ifyouaddedthenumberofeggs,intheaboverecipe,tothenumberofcupsofflour,youwouldarriveatavalidmathematicaladdition,butatotallymeaninglessnumber.Someprogramminglanguageswouldallowyoutodojustsuchanadditionandobedientlyprintoutthemeaninglessanswer.SincePascalrequiresyoutosetupyourconstantsandvariablesinaveryprecisemanner,thepossibilityofsuchameaninglessanswerisminimized.AwellwrittenPascalprogramhasmanycrosscheckstominimizethepossibilityofacompletelyscrambledandmeaninglessoutput.Noticehowever,inthelaststatement,thata"wellwritten"Pascalprogramwasunderdiscussion.Itisstilluptotheprogrammertodefinethedatastructureinsuchawaythattheprogramcanhelppreventgarbagegeneration.Intheend,theprogramwillbenobetterthantheanalysisthatwentintotheprogramdesign.Ifyouareanoviceprogrammer,donotbeintimidatedbyanyoftheabovestatements.Pascalisawelldesigned,usefultoolthathasbeenusedsuccessfullybymanycomputernovicesandprofessionals.Withthesefewwarnings,youarereadytobegin.AdVanCetoChaPter2RetUmtotheTabIeOfCC)meritsCopyright©1986-1997CoronadoEnterprises-1.astupdate,March16,1997GordonDodriH-dodriH-PleaSeemailanycommentsOrSUqqeStiOns.PascalTutorial-Chapter2GettingStartedInPascalYOURFIRSTPASCA1.PROGRAMExampleprogram>TRIVIA1.PAS1.etsgetrightintoaprogramthatreallydoesnothing,butisanexampleofthemosttrivialPascalprogram.1.oadTurboPascal,thenloadTRIVIA1.PASintotheintegratedenvironmentasaworkfile.ThisassumesyouhavebeensuccessfulinlearninghowtousetheTURBOPascalsystem.YoushouldnowhavethemosttrivialPascalprogrampossibleonyourdisplay,andwecantakealookateachparttodefinewhatitdoes.ThefirstlineisrequiredinthestandardPascaldefinitionandcontainstheprogramnamewhichcanbeanynameyoulike,aslongasitfollowstherulesforanidentifiergiveninthenextsection.Itcanhavenoblanks,otherwiseitwouldbeconsideredastwowordsanditwouldconfusethecompiler.ThefirstwordprogramisthefirstofthereservedwordsmentionedearlieranditistheindicatortothePascalcompilerthatthisisthenameoftheprogram.Thesecondword,Puppy_Dog,istheprogramnameitself.Noticethatthelineendswithasemicolon.Pascalusesthesemicolonasastatementseparatorandalthoughallstatementsdonotactuallyendinasemicolon,mostdo,andtheproperuseofthesemicolonwillclearuplaterinyourmind.TURBOPascaldoesnotrequiretheprogramstatement,buttoremaincompatiblewithstandardPascal,itwillsimplyignoretheentirestatement.ItisrecommendedthatyouincludeaprogramnamebothtoaidyourthinkinginstandardPascal,andtoaddalittlemoreindicationofthepurposeofeachprogram.WHATISANIDENTIFIER?Allidentifiers,includingtheprogramname,procedureandfunctionnames,typedefinitions,andconstantandvariablenames,willstartwithanalphabeticalcharacterandbecomposedofanycombination

    注意事项

    本文(Pascal Tutorial 过程式编程语言.docx)为本站会员(李司机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开