| |
| |
Preface | |
| |
| |
Acknowledgments | |
| |
| |
About the Author | |
| |
| |
| |
Hello Pascal | |
| |
| |
| |
Your First Pascal Program | |
| |
| |
Comments | |
| |
| |
Program Heading | |
| |
| |
Syntax and Conventions | |
| |
| |
| |
Displaying Text: Writeln, Write | |
| |
| |
| |
Crunching Numbers | |
| |
| |
Integers and Real Numbers | |
| |
| |
Evaluation of Arithmetic Expressions | |
| |
| |
| |
Using Variables | |
| |
| |
Variable Declaration | |
| |
| |
The Assignment Statement | |
| |
| |
| |
Named Constants | |
| |
| |
| |
Type Conversion: Round, Trunc | |
| |
| |
| |
Reading from the Keyboard: Readln, Read | |
| |
| |
| |
Formatting Output | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Language Elements | |
| |
| |
| |
Standard Data Types and Functions | |
| |
| |
| |
Numeric Data Types | |
| |
| |
Numeric Types in Turbo Pascal | |
| |
| |
| |
Standard Arithmetic Functions | |
| |
| |
Example: The Power Function | |
| |
| |
Example: Grocery Store | |
| |
| |
Turbo Pascal Additional Functions | |
| |
| |
| |
The Character Type: CHAR | |
| |
| |
Standard Functions for Characters | |
| |
| |
Strings in Standard Pascal | |
| |
| |
| |
The String Type | |
| |
| |
Declaration of a String | |
| |
| |
The Length of a String | |
| |
| |
| |
The Boolean Type | |
| |
| |
Simple Boolean Expressions | |
| |
| |
Compound Boolean Expressions | |
| |
| |
Turbo Pascal Operators | |
| |
| |
Precedence of Operators | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Decisions | |
| |
| |
| |
Making Decisions | |
| |
| |
| |
The Simple Decision: If-then | |
| |
| |
Example: Pascal Credit Card | |
| |
| |
Using Blocks | |
| |
| |
| |
The If-then-else Construct | |
| |
| |
| |
The Else-if Ladders | |
| |
| |
Example: A Character Tester | |
| |
| |
| |
Nested Conditions | |
| |
| |
Example: Scores and Grades | |
| |
| |
Tips on the If-Else Puzzles | |
| |
| |
| |
The Multiple Choice: Case | |
| |
| |
Example: A Vending Machine | |
| |
| |
Example: Number of Days in a Month | |
| |
| |
| |
Unconditional Branching: GOTO | |
| |
| |
Repetition Loops | |
| |
| |
| |
Turbo Pascal Features: Exit, Case-Else | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Loops | |
| |
| |
| |
Looping | |
| |
| |
| |
The For Loop | |
| |
| |
Example: Powers of Two | |
| |
| |
Example: The Average | |
| |
| |
| |
Stepping Up and Stepping Down | |
| |
| |
Example: The Factorial | |
| |
| |
| |
Nested Loops | |
| |
| |
| |
The While Loop | |
| |
| |
| |
The Repeat Loop | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Data Architecture | |
| |
| |
| |
Ordinal Data Types | |
| |
| |
Enumerations | |
| |
| |
Subranges | |
| |
| |
| |
The TYPE Section | |
| |
| |
Renaming Types | |
| |
| |
Naming User-Defined Types | |
| |
| |
| |
Arrays as Data Structures | |
| |
| |
| |
One-Dimensional Arrays | |
| |
| |
Example: Scores of One Student | |
| |
| |
Displaying Tabulated Results | |
| |
| |
Declaration of Arrays in the TYPE Section | |
| |
| |
Example: Sorting an Array | |
| |
| |
| |
Two-Dimensional Arrays | |
| |
| |
Example: Scores of Students | |
| |
| |
Array Initialization | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Text Processing | |
| |
| |
| |
Manipulating Text Data | |
| |
| |
| |
Tips on OUTPUT Statements | |
| |
| |
| |
Tips on INPUT Statements | |
| |
| |
Using READLN for Numeric Input | |
| |
| |
Using READ for Numeric Input | |
| |
| |
Using READ for Character Input | |
| |
| |
Using READLN for Character Input | |
| |
| |
Input of Mixed Types | |
| |
| |
Example: Scrambling Letters | |
| |
| |
| |
Reading a Line of Text: EOLN | |
| |
| |
Example: Character Counter | |
| |
| |
| |
Reading a File of Text: EOF | |
| |
| |
Example: Frequency Counter | |
| |
| |
| |
String Manipulation | |
| |
| |
Tips on String Input/Output | |
| |
| |
Example: Sorting Names | |
| |
| |
| |
String Functions and Procedures | |
| |
| |
LENGTH | |
| |
| |
CONCAT | |
| |
| |
COPY | |
| |
| |
POS | |
| |
| |
DELETE | |
| |
| |
INSERT | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Program Architecture | |
| |
| |
| |
Programs and Subprograms | |
| |
| |
| |
Procedures | |
| |
| |
Procedure Definition | |
| |
| |
Passing Values to Procedures | |
| |
| |
Passing Back Values from Procedures | |
| |
| |
| |
Global and Local Variables | |
| |
| |
Example: Sorting Procedure | |
| |
| |
| |
Functions | |
| |
| |
| |
Tips on the Scope of Variables | |
| |
| |
| |
Recursion | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Sets and Records | |
| |
| |
| |
Sets | |
| |
| |
| |
Set Declaration and Assignment | |
| |
| |
Rules and Restrictions | |
| |
| |
| |
Set Operators and Operations | |
| |
| |
Union | |
| |
| |
Intersection | |
| |
| |
Difference | |
| |
| |
Tips on Using Set Operators | |
| |
| |
Relational Operators | |
| |
| |
Example: Text Analyzer | |
| |
| |
| |
Records | |
| |
| |
Record Declaration | |
| |
| |
Accessing Fields | |
| |
| |
The WITH Statement | |
| |
| |
| |
Nesting Records | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Files and Applications | |
| |
| |
| |
Data Files | |
| |
| |
| |
TEXT Files | |
| |
| |
| |
Reading a TEXT File | |
| |
| |
File Variables | |
| |
| |
File Parameters | |
| |
| |
Opening a File for Input: RESET | |
| |
| |
Closing the File | |
| |
| |
File Input Procedures: READ, READLN | |
| |
| |
The EOF and EOLN Functions | |
| |
| |
Example: Disk-File Text Analyzer | |
| |
| |
| |
Displaying a TEXT File | |
| |
| |
Reading a TEXT File as a Set of Strings | |
| |
| |
Reading Multiple Strings | |
| |
| |
| |
Creating a TEXT File: REWRITE | |
| |
| |
File Output Procedures: WRITE, WRITELN | |
| |
| |
Example: Employee File | |
| |
| |
Example: Payroll | |
| |
| |
| |
Non-TEXT Files | |
| |
| |
Example: Payroll System | |
| |
| |
Appending a File | |
| |
| |
| |
Using the File Buffer Variable | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Using Variant Records | |
| |
| |
| |
Variant Records | |
| |
| |
| |
Example: Enhanced Payroll System | |
| |
| |
| |
Deleting Records from the File | |
| |
| |
| |
Updating Records | |
| |
| |
| |
Enhance the Program Modularity | |
| |
| |
Suggestions | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
| |
Pointers and Linked Lists | |
| |
| |
| |
Dynamic Memory Allocation | |
| |
| |
| |
Pointers | |
| |
| |
Pointer Operations | |
| |
| |
Pointers to Records | |
| |
| |
Passing Pointers as Parameters | |
| |
| |
| |
Basics of Linked Lists | |
| |
| |
List Declaration | |
| |
| |
Building a List | |
| |
| |
Reading a List | |
| |
| |
Example: A Linked List Demo | |
| |
| |
Storing Lists in Files | |
| |
| |
Reading Lists from Files | |
| |
| |
Example: A List of Records | |
| |
| |
| |
Searching Lists | |
| |
| |
| |
Deleting Nodes from Lists | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
Answers | |
| |
| |
The Next Step | |
| |
| |
| |
The ASCII Character Set | |
| |
| |
| |
Reserved Words and Standard Identifiers | |
| |
| |
| |
Answers to Drills | |
| |
| |
Index | |