Pascal programming language : Advanced Level / PDF
Pascal programming language : Advanced Level / PDF
Table of Contents
1. Using the Network
1.1. The Network
1.2. Getting Started
1.3. Your home directory
1.4. Running programs
2. MSDOS
2.1. Listing the contents of a disk
2.2. Directory structure
2.3. Directory and filenames ..............................................................................................8
2.4. Reserved and other extensions ....................................................................................8
2.5. The directory tree........................................................................................................8
2.6. Pathnames ..................................................................................................................9
2.7. Relative pathnames.....................................................................................................9
2.8. Moving about the directory tree ..................................................................................9
2.9. Creating and deleting directories ................................................................................10
2.10.Wildcards ...................................................................................................................10
2.11.Command-line switches..............................................................................................11
2.12.Output redirection.......................................................................................................11
2.13.Copying files ..............................................................................................................12
2.14.Other common MSDOS commands ............................................................................12
3. Using the IDE ..................................................................................... 13
3.1. Running Turbo Pascal.................................................................................................13
3.2. The Turbo Pascal Environment...................................................................................13
3.3. Using the Menus.........................................................................................................14
3.4. Using the Online Help ................................................................................................15
3.5. Loading and Saving Files............................................................................................15
3.6. Compiling a Program .................................................................................................15
3.7. Running Programs......................................................................................................16
3.8. Editing Source Code ...................................................................................................17
3.9. Tracing a Program......................................................................................................17
4. The Structure of a PASCAL Program............................................... 18
4.1. Example of a Simple PASCAL Program.....................................................................18
4.2. Structure of a PASCAL Program ................................................................................20
4.3. Data Output: WRITE and WRITELN ........................................................................20
4.4. Formatted Output........................................................................................................20
4.5. Data Input: READ and READLN ...............................................................................21
4.6. The Assignment Statement .........................................................................................21
4.7. Arithmetic Operators and Functions ...........................................................................21
4.8. Exercises - 1 ...............................................................................................................23
4.9. Exercises - 2 ...............................................................................................................23
5. Conditional and Compound Statements ......................................... 25
5.1. Boolean Values and Relational Operators ...................................................................25
5.2. Logic Operators ..........................................................................................................25
5.3. Boolean Variables.......................................................................................................26
5.4. IF...THEN...ELSE ......................................................................................................27
5.5. Compound Statements ................................................................................................27
5.6. Exercises - If..Then..Else ............................................................................................28
6. The CASE Statement......................................................................... 30
6.1. Syntax of the CASE Statement....................................................................................30
6.2. Using Many Labels In A Single Case..........................................................................31
6.3. Simple Menus.............................................................................................................31
6.4. Exercises ....................................................................................................................32
7. Arrays and Loops .............................................................................. 33
7.1. Single Dimensional Arrays .........................................................................................33
7.2. Two Dimensional Arrays ............................................................................................34
7.3. Higher Dimensional Arrays ........................................................................................34
7.4. Exercises - Arrays.......................................................................................................34
7.5. Loops..........................................................................................................................35
7.6. The FOR..DO loop......................................................................................................35
7.7. The REPEAT..UNTIL loop.........................................................................................37
7.8. The WHILE..DO loop.................................................................................................37
7.9. Comparison of REPEAT..UNTIL and WHILE..DO loops ...........................................38
7.10.Exercises - FOR, REPEAT and WHILE loops.............................................................38
8. Strings and Text Files ....................................................................... 41
8.1. String Variables..........................................................................................................41
8.2. Operations On Strings ................................................................................................41
8.3. Reading and Writing Characters in a String................................................................42
8.4. Comparing Strings......................................................................................................42
8.5. Text Files....................................................................................................................43
8.6. File Variables .............................................................................................................43
8.7. Reading From a Text File ...........................................................................................43
8.8. Creating a New Text File............................................................................................44
8.9. Appending Data to a Text File ....................................................................................44
8.10.The Printer Text File ..................................................................................................44
8.11.Exercises - Text Files..................................................................................................45
9. Procedures - 1.................................................................................... 47
9.1. Top-Down Design.......................................................................................................47
9.2. Simple Procedures ......................................................................................................47
9.3. Procedures and the Stack ............................................................................................48
9.4. Value Parameters - Parameters for Input.....................................................................49
9.5. String Parameters - Using Type ..................................................................................50
9.6. Some More Standard Turbo Pascal Procedures............................................................51
9.7. Exercises - Procedures 1 ............................................................................................52
10. Procedures - 2.................................................................................... 53
10.1.Variable Parameters - Parameters for Input and Output ..............................................53
10.2.Declaring Variable Parameters ...................................................................................53
10.3.Exercises - Procedures with VAR Parameters .............................................................54
10.4.Using String Types in Var Parameters - Relaxing Type Checking...............................55
10.5.Procedures Which Call Other Procedures....................................................................56
10.6.Creating a Library Unit...............................................................................................56
10.7.The Structure of a Turbo Pascal Unit (TPU)................................................................56
10.7.1. INTERFACE PART ........................................................................................................57
10.7.2. IMPLEMENTATION PART ...............................................................................................57
10.8.Example of a TPU ......................................................................................................57
10.9.Using a TPU...............................................................................................................58
10.10. Exercises - Writing a TPU ....................................................................................58
11. Functions ........................................................................................... 60
11.1.What are Functions? ...................................................................................................60
11.2.Declaring Simple Functions........................................................................................60
11.3.Exercise - Writing Functions ......................................................................................61
11.4.Passing Arrays as Parameters to Subprograms ............................................................61
11.5.Small Project - Implementing a Stack .........................................................................61
11.6.Nature of problem to be Solved ...................................................................................62
11.7.Designing the Interface...............................................................................................62
11.8.Designing the Implementation ....................................................................................62
11.9.Exercises - Stack Unit.................................................................................................63
12. Enumerated Types, Ranges and Sets.............................................. 64
12.1.Enumerated Types ......................................................................................................64
12.2.Subrange Types ..........................................................................................................65
12.3.Set Types and Sets ......................................................................................................66
12.4.Exercises - Enumerated types, Ranges and Sets...........................................................68
13. Static Records and Random Files ................................................... 69
13.1.The RECORD Type....................................................................................................69
13.2.Files of Records ..........................................................................................................71
13.3.Opening a Record File ................................................................................................72
13.4.Reading and Writing Records .....................................................................................73
13.5.Other File Operations .................................................................................................73
13.6.File Functions.............................................................................................................73
13.7.Handling File I/O Errors.............................................................................................74
13.8.Using Random-Access Files - Some Notes ..................................................................74
13.9.Exercises - Random Access Files ................................................................................74
14. Recursion ........................................................................................... 76
14.1.A Simple Example of Recursion .................................................................................76
14.2.Recursive vs. Iterative Strategies.................................................................................76
14.3.Characteristics of Recursive Algorithms .....................................................................77
14.4.The Uses of Recursion ................................................................................................77
14.5.Examples of Recursion ...............................................................................................77
14.6.Exercises - Recursion..................................................................................................
Pascal programming language : Advanced Level / PDF
0 commentaires: