Pascal Tutorial 过程式编程语言.docx
《Pascal Tutorial 过程式编程语言.docx》由会员分享,可在线阅读,更多相关《Pascal Tutorial 过程式编程语言.docx(102页珍藏版)》请在课桌文档上搜索。
1、PascalTutorial-IntroIntroductionIFYOUKNOWNOTHINGABOUTPASCA1.AssumingthatyouknownothingatallaboutPascal,andinfact,thatyoumayknownothingaboutprogrammingingeneral,wewillbegintostudyPascal.IfyouarealreadysomewhatfamiliarwithprogrammingandespeciallyPascal,youW川probablywanttoskipveryquicklythroughthefirst
2、fewchapters.Youshouldatleastskimthesechapters,andyoushouldreadtheremainderofthisintroduction.Afewcommentsareinordertogetusstartedintherightdirection.ThesampleprogramsincludedwiththistutorialaredesignedtoteachyouthebasicsofPascalandtheydonotincludeanycleverortrickycode.Nearlyalloftheprogramsarereally
3、quitedumbasfarasbeingusefulprograms,butallwillteachoneormoreprinciplesofPascal.Ihaveseenonetutorialthatincludeda12pageprogramasthefirstexample.Infacttherewereonly2exampleprogramsintheentiretutorial,anditwasimpossibletogleantheessentialsofprogrammingfromthatsystem.Forthisreason,Iwillcompletelybypassa
4、nylongprogramsuntiltheveryendofthistutorial.Inorderto川UStratefundamentalconceptsusedinPascalprogramming,allprogramswillbeveryshortandconciseuntilwereachthelastchapter.1.ARGERPASCA1.PROGRAMSChapter16hassomeratherlargeprogramstoillustratetoyouhowtowritealargeprogram.Itwouldbeadisservicetoyoutoshowyoua
5、lloftheconstructsofPascalandnotshowyouhowtoputthemtogetherinameaningfulwaytobuildalargeprogram.AftercompletingallofthefundamentalsofPascal,itwillthenbeveryeasyforyoutousethetoolslearnedtobuildaslargeaprogramasyoudesireorrequireforyournextprogrammingproject.AnotherproblemIhavenoticedinexampleprograms
6、istheuseofonewordforalldefinitions.Forexample,asortprogramisstoredinafilecalledSORT,theprogramisnamedSort,andvariouspartsoftheprogramarereferredtoasSortl1Sort2,etc.Thiscanbeconfusingsinceyouhavenoideaiftheprogramnamemustbethesameasthefilename,orifanyoftheothernameswerechosentobethesamebecauseofsomeo
7、bscurerulenotclearlydocumented.Forthisreason,theexampleprogramsusecompletelyarbitrarynameswheneverthechoiceofanameaddsnothingtothereadabilityorclarityofaprogram.Asan川UStrationofthistthefirstprogramisnamedPuppy_Dog.Thisaddsnothingtotheunderstandingoftheprogrambutdoesillustratethattheprogramnamemeansn
8、othingtothePascalcompilerconcerningwhattheprogramdoes.DuetothefundamentaldesignofthePascallanguage,certainwordsarereservedandcanonlybeusedfortheirdefinedpurposes.ThesearelistedinyorTURBOPascalreferencemanual.Allofthesampleprogramsinthistutorialarewrittenwiththereservedwordsinalllower-caseletters,and
9、theuservariablesinlowercasewiththefirstlettercapitalizedsincethisisbecominganacceptedindustrystandard.Dontworryaboutwhatreservedwordsareyet,theywillbecompletelydefinedlater.Inthistutorial,allreservedwords,typenames,variablenames,andprocedureandfunctionnameswillbelistedinboldfacetypewithinthetextasan
10、aidtothestudent.whatIsacompiler?TherearetwomethodsusedtorunanycomputerprogramthatiswritteninareadableformofEnglish.Thefirstmethodistouseaninterpreter.AninterpreterisaprogramthatlooksateachlineoftheEnglishprogram,decideswhattheEnglishonthatlinemeans,anddoeswhatitsaystodo.Ifoneofthelinesisexecutedrepe
11、atedly,itmustbescannedandanalyzedeachtime,greatlyslowingdownthesolutionoftheproblemathand.Acompiler,ontheotherhand,isaprogramthatlooksateachEnglishstatementonetimeandconvertsitintoacodethatthecomputerunderstandsdirectly.Whenthecompiledprogramisactuallyrun,thecomputerdoesnothavetofigureoutwhateachsta
12、tementmeans,itisalreadyinaformthatthecomputercanrundirectly,resultinginmuchfasterexecutionoftheprogram.ThistutorialiswrittenespeciallyforBorlandInternationalsTURBOPascalcompilersversion5.0through7.0.Theseareveryhighqualitycompilersthatcandonearlyanythingyouwillaskthemtodosincetheyaresoflexible.Theor
13、iginalintentofthistutorialwastowriteitinsuchawaythatitwouldbecompletelygenericandusablewithanygoodPascalcompiler.TheprogrammersatBorlandincludedagreatmanynonstandardaidsforthePascallanguageandresultedinaverygoodproductthathasdominatedthemarketformicrocomputers.Tocompletelyomitalloftheextensionswould
14、dothoseofyouwiththeBorlandcompilerarealdisservice,andtoincludetheextensionswouldnotallowothercompilerstobeusedeffectivelywiththistutorial.ThedecisionwasmadetousetheBorlandextensionswhichmaymakethetutorialdifficulttousewithothercompilers.IfyouhaveaneedtousePascalwithsomeothercompiler,TURBOPascalissoi
15、nexpensivethatitwouldbeawisedecisiontopurchaseacopysolelyforthepurposeoflearningthePascalprogramminglanguage,thenmovingtotheothercompileronaminicomputeroramainframeusingtheaccumulatedknowledgetoveryquicklylearntheextensionsprovidedbythatparticularcompiler.Atanyrate,thistutorialwillnotteachyoueveryth
16、ingyouwilleverneedtoknowaboutPascal.Itwill,however,teachyouthefundamentalsandtheadvancedfeaturesofPascal,butofevenmoreimportanceistheknowledgeofPascalterminologyneededtoprogressonyourownintomoreadvancedtopicsofPascalandprogrammingingeneral.Youwillfindthatexperiencewillbeyourbestteacher.WHICHVERSIONO
17、FTURBOPASCA1.?SomeoftheexampleprogramswillnotworkwithsomeoftheearlierversionsofTURBOPascal.Thisisprimarilyduetothefactthatobjectorientedprogrammingcapabilitieswereaddedtoversion5.5,andimprovedoninlaterversions.Mostoftheexampleprogramswillworkwithanyversionhowever.Itshouldbepointedoutthateachsuccessi
18、veversionofTURBOPascalhasbeenanimprovementoverthepreviousversionsinceadditionalcapabilitieshavebeenadded,andeachnewonecompilesalittlefasterandresultsinsmallerbutfasterexecutablecodethanthepreviousversion.AnyoftheversionsofTURBOPascalcanbeusedtolearntoprograminPascal,sowhicheverversionyouhaveonhandwi
19、llbeadequate.1.ater,whenyoubecomemoreversedinprogrammingtechniques,youmaywishtoupgradetotheabsolutelatestversion.EAR1.YVERSIONSOFTURBOPASCA1.MostofthefileswillcompileproperlywithTURBOPascalversions2.0through4.0.Nowarningwillbegivenaboutwhichfileswillnotcompilewiththeseversionssincetheyhavebeensupers
20、ededforsolong.Ifyouarestillusingoneoftheearlierversions,itwouldbegoodforyoutopurchaseanewerversionbecauseoftheflexibility.WHATABOUTTURBOPASCA1.VERSION5.5&NEWER?Chapters14and15ofthistutorialarewrittenespeciallyforTURBOPascalversion5.5andnewertodiscusstheuseofobjectorientedprogrammingandhowtousetheBor
21、landextensions.Sincethetopicofobjectorientedprogrammingisaverylargeanddiversefieldofstudyandonlyalimitedspaceisavailabletodiscussitinthistutorial,thesechapterswillgiveyouonlyabriefoverviewofwhatitisandhowtouseit.Youwillfind13completeexampleprogramstogetyoustartedinthisnewandverymeaningfulendeavorand
22、thisintroductionshouldwhetyourappetitetocontinueyourstudyinmoredepth.IfyouareusinganearlyversionofTURBOPascalwithouttheobjectorientedextensions,itwouldpayyoutoupgradesoyoucanlearnhowtousethisnewprogrammingmethod.Objectorientedprogramminghasthepotentialtogreatlyimprovethequalityofyourcodeandtoreducet
23、hedebuggingtimerequired.PREPARATIONFORUSEOFTHISTUTORIA1.CopytheexamplefilesintoyourTURBOPascalworkingdirectoryandyouarereadytobegin,providedofcoursethatyouhavealreadylearnedhowtostarttheTURBOsystemandhowtoeditaPascalfile.IfyouarenotusingTURBOPascal,youwillstillbeabletocompileandexecutemanyofthesePas
24、calfiles,sincemostoftheexamplesusestandardPascalsyntax.TherewillbesomestatementsusedwhichareuniquetoTURBOPascalandwillnotworkwithyourcompiler.Thiswillbeespeciallytruewhenyoucometothechapteronstandardinputandoutputsincethisiswheremostcompilersdiffer.Unfortunately,thisisoneofthemostimportantaspectsofa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Pascal Tutorial 过程式编程语言 程式 编程 语言
链接地址:https://www.desk33.com/p-1417583.html