ebook img

A Practical Introduction to Pascal — with BS 6192 PDF

250 Pages·1982·17.395 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview A Practical Introduction to Pascal — with BS 6192

ISBN 978-0-333-33340-2 9 780333 333402 Macmillan ComputerScienceSeries ConsultingEditor ProfessorF.H.Sumner,UniversityofManchester S.T.AllworthandR.N.Zobel, Introduction toReal-timeSoftwareDesign. secondedition IanO.Angell andGarethGriffith,High-resolutionComputerGraphicsUsing FORTRAN77 IanO.Angell andGarethGriffith,High-resolutionComputerGraphics UsingPascal M.Azmoodeh,AbstractDataTypesandAlgorithms C.BamfordandP.Curran,DataStructures,FilesandDatabases PhilipBarker,AuthorLanguagesforCAL A.N.BarrettandA.L.Mackay,SpatialStructureandtheMicrocomputer R.E.Berry, B.A.E.MeekingsandM.D.Soren,ABookonC,secondedition P.Beynon-Davies,Information SystemsDevelopment G.M.Birtwistle,DiscreteEventModelling onSimula B.G.BlundellandC.N.Daskalakis,UsingandAdministeringanApolloNetwork B.G.Blundell,e.N.Daskalakis,N.A.E.Heyes andT.P.Hopkins,An IntroductoryGuidetoSilvarLiscoandHiloSimulators T.B.Boffey,GraphTheory inOperationsResearch RichardBomat,UnderstandingandWritingCompilers LindaE.M.Brackenbury,DesignofVLSISystems-APracticalIntroduction G.R. BrookesandAJ.Stewart,Introduction tooccam2ontheTransputer J.K.Buckle,SoftwareConfigurationManagement W.O.BurnhamandA.R.Hall,PrologProgramming andApplications P.e.CaponandPJ.Jinks, CompilerEngineeringUsingPascal J.e.Cluley,lnteifacingtoMicroprocessors J.C.Cluley,lntroductiontoLow-LevelProgrammingfor Microprocessors RobertCole,ComputerCommunications,secondedition DerekColeman,AStructuredProgrammingApproachtoData AndrewJ.T.Colin,FundamentalsofComputerScience AndrewJ.T.Colin,ProgrammingandProblem-solvinginAlgol68 S.M.Deen, FundamentalsofDataBaseSystems S.M.Deen, PrinciplesandPracticeofDatabaseSystems C.Delannoy,TurboPascalProgramming TimDenvir,lntroductiontoDiscreteMathematicsforSoftware Engineering D.Englandetal.,ASunUser's Guide K.e.E.Gee,Introduction toLocalAreaComputer Networks J.B.Gosling, DesignofArithmeticUnitsfor DigitalComputers M.G.Hartley,M.Healey andP.G.Depledge,MiniandMicrocomputerSystems Roger Hurty,280AssemblyLanguage ProgrammingforStudents RolandN.!bbettandNigelP.Topham,ArchitectureofHighPerformanceComputers, Volume! RolandN,!bbettandNigelP.Topham,ArchitectureofHighPerformanceComputers, VolumeII PatrickJaulent,The68000- HardwareandSoftware P.Jaulent, L.BaticleandP.Pillot,68020-30Microprocessorsandtheir Coprocessors J.M.KingandJ.P.Pardoe,ProgramDesignUsingISP-APractical Introduction E.V.Krishnamurthy,lntroductoryTheoryofComputerScience V.P.Lane,Security ofComputerBasedInformation Systems GrahamLee,FromHardware toSoftware-AnIntroduction ToComputers (continuedoverleaf) A.M.ListerandRD.Eager,FundamentalsofOperatingSystems,fourthedition TomMannsandMichaelColeman,SoftwareQualityAssurance BrianMeek,Fortran.Pldl andtheAlgols A.MevelandT.Gueguen,Sma//talk-80 R.J.Mitchell,MicrocomputerSystemsUsingtheSTEBus Y.NishinumaandR.Espesser,UNIX- FirstContact PimOets,MS-DOSandPC-DOS-APracticalGuide.secondedition AJ.Pilavakis, UNIXWorkshop ChristianQueinnec,USP EJ.Redfern,IntroductiontoPascalforComputationalMathematics GordonReece,MicrocomputerModellingbyFiniteDifferences W.P.Salman,O.TisserandandB.Toulout,FORTH L.E.Scales,IntroductiontoNon-LinearOptimization PeterS.Sell,ExpertSystems- APracticalIntroduction A.G.Sutcliffe,Human-ComputerInterfaceDesign ColinJ.TheakerandGrahamR Brookes,APracticalCourseonOperatingSystems M.R.Tolhurstetal.•OpenSystemsInterconnection J-M.Trio,808~n88ArchitectureandProgramming AJ.Tyrrell,COBOLfromPascal M.J.Usher,InformationTheoryforInformationTechnologists B.S.Walker,UnderstandingMicroprocessors ColinWalls,ProgrammingDedicatedMicroprocessors lRWilsonandA.M.Addyman,APracticalIntroductiontoPascal- withBS6I92. secondedition Non-series RoyAnderson.Management.InformationSystemsandComputers 10.Angell,AdvancedGraphicswiththeIBMPersonalComputer J.E.BinghamandG.W.P.Davies.PlanningforDataCommunications B.V.CordingleyandD.Chamund,AdvancedBASICScientificSubroutines N.Frude,AGuidetoSPSSIPC+ BarryThomas.APostScriptCookbook A Practical Introduction to Pascal -with BS 6192 Second Edition I.R.Wilson Department ofComputer Science, University ofManchester A.M.Addyman Department ofMathematics and Computer Science, University ofSalford M MACMILLAN ©I.R.WilsonandA.M.Addyman 1978.1982 ©BS6192: 1982.BritishStandards Institution Allrightsreserved.Noreproduction.copyortransmission ofthispublicationmaybemade withoutwrittenpermission. Noparagraphofthispublicationmaybereproduced.copiedor transmitted savewithwrittenpermissionorinaccordance with theprovisionsoftheCopyright,DesignsandPatentsAct 1988, orunderthetermsofanylicencepermitting limitedcopying issuedbytheCopyright LicensingAgency,33--4AlfredPlace. London WCIE7DP. Anypersonwhodoesanyunauthorisedactinrelationto thispublicationmaybeliabletocriminalprosecutionand civilclaimsfordamages. Firstedition 1978 Reprinted 1979(twice), 1980(twice), 1981 Secondedition 1982 Reprinted 1983(withminorcorrections).1984(twice),1985, 1987. 1990 Publishedby MACMILLAN EDUCATIONLTD Houndmills,Basingstoke,HampshireRG212XS andLondon Companiesandrepresentatives throughout theworld Typesetin 10/12PressRomanby ThamesTypesetting,Abingdon . ISBN 978-0-333-33340-2 ISBN 978-1-349-06364-2 (eBook) DOI 10.1007/978-1-349-06364-2 to Alleyn, Fiona,Jamie, Kirstie Hilary, Rebecca, Sarah, Helen and Amy Contents Preface xi Introduction I 2 TheForm ofaProgramandBasicCalculations 4 2.1 TheStyleofWritinginPascal 4 2.2 TheGeneralFormofaProgram 4 2.3 TheAssignmentStatementandSimpleArithmetic 5 2.4 ACompleteProgramwithSimpleInput/Output 6 2.5 ReadablePrograms 7 3 BasicControlConstructs 9 3.1 Repetition 9 3.2 Choice-TheifStatement 13 3.3 Selection-ThecaseStatement 16 3.4 AdviceonProblem-solving 17 4 Variables,Constantsand Expressions 21 4.1 TheDifferentTypesofVariableandConstant 21 4.2 ThePrecedenceofOperators 21 4.3 Real 22 4.4 Integer 23 4.5 Character 2S 4.6 TheBasisofDecisions-Boolean 27 4.7 MoreComplexConditions 28 5 AnIntroductionto InputandOutput 32 5.1 readandreadln 32 5.2 write andwriteln 33 5.3 TheDifferentStylesofOutput 35 6 AnIntroductionto ProceduresandFunctions 38 6.1 CallingandDefiningaProcedure 38 6.2 VaryingtheAction-ValueParameters 39 6.3 ObtainingResults-VariableParameters 40 6.4 CalculatingOneValue-Functions 42 6.5 TheScopeofIdentiflers 44 viii APracticalIntroductiontoPascal 7 DataTypes 48 7.1 The Concept ofType 48 7.2 Type Definitions 49 7.3 SimpleTypes 50 7.4 StructuredDataTypes 55 7.5 DataRepresentation 55 7.6 Type Compatibility 56 7.7 UsingOrdinalTypes 57 7.8 PrintingonaFixedWidthPrinter 58 8 StructuringMethods I-TheSequentialFile 61 8.1 The Concept ofaSequence 61 8.2 The Sequential File 61 8.3 InternalandExternal Files 64 804 Textfiles 64 8.5 ASimpleTextEditor 66 9 StructuringMethods2-TheSet 70 9.1 AnIntroductionto SetTheory 70 9.2 SetsinPascal 71 9.3 ABingo-playingProgram 74 10 StructuringMethods3-TheArray 78 10.1 AnIntroductionto Arrays 78 10.2 ArraysofArrays 79 10.3 Arraysofchar 80 lOA Packingand Unpacking 81 10.5 TheArrayinUse 82 10.6 ConformantArrayParameters 86 11 StructuringMethods4-TheRecord 93 II.l AnIntroductionto Records 93 11.2 Records inPascal 93 II.3 Thewith Statement 95 11.4 ASimpleApplicationofRecords-ACardGame 97 12 StructuringMethods5- TheVariant 102 12.1 The NeedforType Unions 102 12.2 Record VariantsinPascal 103 12.3 UsingRecordVariants 105 1204 CalculatingtheAreaofaGeometric Figure 105 Contents ix 13 AdvancedUsesofProceduresand Functions 107 13.1 TheUseofProcedures forTop-down Design 107 13.2 AfurtherDiscussionofScope 108 13.3 Procedural andFunctionalParameters 110 13.4 Recursion 112 13.5 TheDirectiveforward 115 13.6 Thegoto Statement 116 13.7 Restrictionsontheuseofgotosand Labels 117 14 DynamicDataStructures 119 14.1 Static and DynamicVariables 119 14.2 TheCreation ofDynamicVariables 121 14.3 UsingPointers 122 14.4 Re-usingDynamicallyAllocated Storage 124 14.5 TheLondon Underground Problem 125 AppendixI PascalSyntaxDiagrams 135 AppendixII ListofPascalReservedWords 143 AppendixIII AnswerstoExercisesandSchemaforSelectedProblems 144 Bibliography 162 ThePascalStandard 163 Index 237 Preface Sincethe firsteditionofthis book waswrittenin1977,there hasbeena tremendousincreaseintheuseofPascal.Thisincreasedusehashad two significanteffects. (1) Ithasproducedabetterunderstandingofthe facilitiesofPascalandtheir use. (2) Ithasfosteredthe productionofthe ISOstandardforPascal. Thissecondeditionreflects both this betterunderstandingandthe clarificationsandchangesto Pascalwhichhaveresultedfrom theproduction ofthe BSljlSO Pascalstandard.Thestandard(BS6I92,whichsuppliesthe technicalcontentforISO7185) isthe definitivedocumentonPascal;it is reproducedinitsentiretyfrom page163ofthe book. Mywork onthe PascalStandardhasconvinced methat the descriptionofaprogramming languagemay betutorial,oritmaybedefmitive, oritmaybeneither! The chaptersofthis book donot constituteadefmitive descriptionofPascal.They areessentiallytutorial. The book isbasedonanintroductorylecturecoursegivenatManchester. In additionto lectures, the courseconsistsoftwo kindsofpractical work. The firstisbasedonthe solution ofshort pencil-and-paper exercises.Thesecond requiresthe studentto write completeprogramsandrun them usinginteractive computerterminals.Eachchapterofthe book concludeswith exercisesand problemssuitable forthese purposes.Although solutions to allofthese arenot presentedinthe book,teaching staffmay obtainthem byapplicationto the authors. The fullPascallanguageispresentedinapractical manner, with reference to exampleapplications.Theimportanceofthe designofdata structuresinthe solution ofaproblemisrecognisedbydevotingsevenchaptersto thistopic. It isintendedthatthe book willbeofuseto first-timestudentsand tomore experiencedprogrammersnot yet familiarwith Pascal. Finally,Iwouldliketo thankallthose people from many countrieswhohave helped mefulfilmyambitionofcreating anISOPascalstandardandwhoat the sametimehaveimproved myunderstandingofPascal.Spacepreventsme fromnamingthemall,but specialmentionshould bemade ofBillFindlay, ChrisKirkham,Jim Miner,BillPrice,ArthurSale,DavidWattandJimWelsh.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.