Vous êtes sur la page 1sur 92

Chapter 1

Introduction

Basic competencies
1. Students are able to understand the basic concepts of the program,
programming and programming languages
2. Students are able to finding pascal language development
3. Students are able to installing Turbo Pascal 7.0 program
4. Studentsare able to understand the basic concepts of programming using Turbo
Pascal 7.0

A. Basic Concepts Program, Programming and Programming


Languages
1. Program, Programming and Programming Languages
The term program or computer programs may be familiar to our ears
again, so is the term programming. Courses or programs are instructions given
to the computer to perform a specific task. while programming is an attempt to
make the code, code can be recognized by the computer.
Just as humans are created with different language, religion, ethnicity
and class, also has a computer language known as a programming language.
The difference in human languages and computer languages lies in the
diversity of languages owned. Humans have thousands or even millions of the
language used to communicate between humans while computers only speak
one language yitu machine language. Machine language consists of yaiti binary
digits 0 and 1. Language with code like this difficult to learn that a computer
programming language that was created to help people make the program code
known as a programming language.
Programming languages are divided into two levels (although there are
some books that define 3 levels), namely: Low Level Programming Languages
(Low Level Language) and the High-Level Programming Language (High

1
Level Language). Low-level programming language is a language that can not
be understood by humans because it is a sequence of numbers 0 and 1.
Example: Machine Language, Assembly Language. While high-level
programming language is a language approaching human language that is
easily understood by humans. Example: FORTRAN, PASCAL, ALGOL,
COBOL, etc.
2. Language Translator
High-level languages are not necessarily understood by the computer
because the computer only understands machine language. To overcome this
we can use a translator known as language translator. Language translator
assigned to translate the high-level language into machine language so that it
can be run by a computer. The process of translating the programming
language known as Compilation Program. Keep in mind that the language
translator used must be in accordance with the code you want translated. If we
write a program using the PASCAL language, then the language that we use
the translator must also equal the language translator for the language
PASCAL
The workings of language translator can be seen in the following
scheme:

Translator

Source Object
Program Program

CPU

2
Object
Program
Data Output

CPU
Figure 1.1 Schematic Working Language Translator
Figure 1

Language translator is divided into 2: Interpreter and Compiler.


Although the principle works the same, compiler and interpreter are quite
striking differences. In the interpreter, the code will be translated perbaris so
when encountered an error, the previous line will still be executed. This is very
different from the compiler that translates all source code before finally
running, so if there is an error on a particular line, compiler will not
mengeskusi previous lines. For more details, see the following illustration:

Like a visit to the UK, while you can not speak English. You take the
initiative to hire a translator to say hello to one of the people you meet. List of
the sentence is:
1. Good Morning <
2. My name hendra
3. I am originally from Indonesia

3
Concept Interpreter

List Sentences from us Indonesian


Translater
1. Good Morning 1. Selamat Pagi
1. Selamat Pagi
2. My name is 2. …….
2. Namaku Irwan
Irwan 3. ……
3. Saya berasal ..
3. I am from UK

Figure 1.2 Illustration Interpreter

Translater
List Sentences from us Warga Inggris
1. Good Morning
1. Selamat Pagi 1. Good Morning
2. My name is Henry
2. Namaku Henry 2. My name is Henry
3. I come from
3. Saya berasal dari 3. I come from
Indonesia
Indonesia Indonesia

Figure 1.3 Compiler Interpreter

3. Step Programming

The steps we should take at the time will do the programming are:
1. Creating Algorithm and Flowchart
2. Writing a program using a programming language
3. Test the program correctness
4. Improvement program if there is an error
5. Running the program

4
Syntax errors are errors that other so-called logic errors, mistakes at this stage
generally cause bugs (read: bag). While efforts to find fault with a program called
debugging.

B. History of Pascal
Pascal is a high level language (high level language) whose orientation in
all-purpose, designed by Professor Niklaus Wirth at the Technical University of
Zurich, Switzerland. Name Pascal was taken in recognition of Blaise Pascal, the
famous mathematician and philosopher of 17th century in France. Professor
Niklaus Wirth introduced the first Pascal compiler for the CDC 6000 computer
(Control Data Corporation), published in 1971 with the goal of helping teach a
computer program systematically, in particular to introduce structured
programming.
In a short time, Pascal language has become popular among college
students and is the language taught at several universities. Some computer
professionals also began to switch to the language Pascal. In fact, Pascal is the
language of the most popular fast compared to languages other high-level
computer.
Standard Pascal is a Pascal language defined by K.Jensen and Niklaus
Wirth. Pascal manifests the many different standards to what has been defined by
K. Jensen and Niklaus Wirth. Standard Pascal in Europe defined enumerated by
the ISO (International Standards Organization) and the United States by the
cooperation between the ANSI (American National Standards Institute) and IEEE
(Intitute of Electrical and Electronics Engineers).
Some versions of Pascal that has been circulating in the market, including
pascal UCSD (University of California at San Diego Pascal), MS-Pascal (Pascal
Microsoft), Apple Pascal, Turbo Pascal and others. Until now for micro computers
and personal, Turbo Pascal is a Pascal language versions of the most popular and
widely used. Turbo Pascal compiler favored, due primarily interactive, like the

5
interpreter just like. Additionally Turbo Pascal follows the definition of standards
as defined by K. Jensen and Niklaus Wirth in the Pascal User Manual and Report.
Turbo PASCAL is copyright of Borland Inc.. and can be used on PC-DOS
operating system, MS-DOS, CPM-86 and CP/M-80.
PASCAL growing popularity with the development of PC. There are
several Compiler PASCAL, one of which is a TURBO PASCAL released by
Borland International. TURBO PASCAL 7.0 was released in 1992 that has:
1. Compiler (to compile the program into an object that is understood by the
computer
2. Debugger (to help debugging a program)
3. Linker (to combine object files and file pustakadan form Executable File)
4. Editor (for writing program source / source code)

C. Installing Turbo Pascal 7.0


1. First, To install Turbo Pascal 7.0 you must have the master. Perform step
installation program by selecting the Control Panel and then Add and Remove
Programs menu and then Add New Programs,
2. Select CD or Floppy and then select Browse to locate the master Turbo Pascal
7.0 install you will then select Finish

6
Figure 1.4 Install Pascal 1
3. Wait for the installation process run and then click Next after confirming the
addition of icons appear pascal. After that wait for the installation process will
proceed to completion.

7
Figure 1.5 Install Pascal 2

4. Move TPX formed Icon to the Desktop

Figure 1.6 Install Pascal 3

D. Exercise
1. What is there to know about programs, programming and programming
languages?
2. Identify and give examples of programming languages!
3. What is a language translator and explain how it works!
4. What is the difference Compiler and Interpreter?
5. What are the advantages of Turbo Pascal 7.0?

8
Chapter 2
Editor Pascal

Basic competencies:

1. Students are able to know PASCAL editor to create program code


2. Students are able to use the editor to create the source code PASCAL

A. Running Turbo Pascal Editor 7.0


After the program we install Turbo Pascal 7.0 on our computer, the next step is
to open the PASCAL editor to write the program. The steps that we can do to run
Turbo Pascal Editor 7.0 is as follows:
1. Before you work you should create a special folder to store our practice
example folder called: TRAIN (eg in the directory D: \ or the other).
2. Run Turbo Pascal 7.0 program from your desktop or Start - Programs - Turbo
Pascal 7 - TPX

Figure 2.1 Menu Editor TURBO PASCAL 7.0 Desktop


Or

9
Figure 2.2 Menu Editor 7.0 TURBO PASCAL Start
3. Editor will appear early Turbo Pascal 7.0 as follows:

Figure 2.3 Initial View Turbo Pascal Editor


4. The next step is to drive to the working directory that you created.

10
B. Know Your Environment Editor Turbo Pascal 7.0
Turbo Pascal mepunyai the menu line is at the top which consists of:
1. File
a. New, create a new program
b. Open, Calling a program stored on disk
c. Save, Save the program with the same name
d. Save As, Save the program with a different name
e. Save All, save all the programs on the screen
f. Dir Change, change the active drive for the storage and retrieval file.
g. Print, to print
h. Printer Setup, the printer settings
i. DOS Shell, Go to the DOS for a while, to return to Turbo Pascal Type
EXIT and then Enter
j. Exit, Exit Turbo Pascal
2. Edit
a. Undo, restore the last deleted
b. Redo, Undo delete return on
c. Cut, remove the blocks to be moved to another place
d. Copy, copy block
e. Paste, showing the cut or copy the contents of the blog
f. Show Clipboard, displays the contents of the clipboard
3. Search
a. Find, to seek or commands written on a program in the works
b. Replace, to replace words or commands written on a program in the works
c. Search Again, look for longer words or commands written on a program in
the works
d. Go to line number, go to the line in question
e. Show last compiler error, indicating the last compilation error
f. Find the error, fault finding

11
g. Find procedure, searching procedure is
h. Previous Browserdan Globals, showing various fingsi and Procedures is in
pascal
i. Objects and the Units, to search for object names and units
j. Symbol, look for the symbol
4. Run
a. Run, to run a program
b. Step Over, Step over this have a way of working that is almost the same as
the Trace Into, only if the statement is a procedure or function, the whole
subroutine will be done at once and the debugger will stop at the statement
after the call to the subroutine
c. Trace into, command is used to execute the next line, if there is a call to a
subroutine, then the tracking will start from the first statement of the
subroutine.
d. Go to cursor, option is used to start / continue execution of the program
begins execution starts from the current position to where the cursor is.
e. Program reset, option is used to tell the Turbo Pascal that you are done
with the correction-rectification and initialize debugger for another
operation.
f. Parameters, run the program parameters
5. Compile
a. Compile, command is used to compile the program (find fault) or we can
also say that the program that we have made earlier with pascal language
be translated into computer language that the computer understands each
other what we command
b. Make, This option is used to enable the make command, if the primary file
has been given a name, then the file will be compiled, if not the last file
that was loaded in the editor will be compiled .. This option is very useful

12
if there are several programs that are physically separate but logically
constitute a unity.
c. Build, command is similar to the make command, only this build
command nature free, while the make command will only compile files
other than the files used.
d. Primary File, command is used to declare that file. PAS will be compiled
at the time make [F9] or build [Alt + C + B] is enabled.
e. Clear primary file, delete the primary file
f. Information, this command is used to display the information window of
the program. PAS you're using, including the size of the source code [in
the source and the line], the size of the file. EXE or. Cemetery in byte and
data.
6. Debug
a. Breakpoints, set a line as a breakpoint. In the breakpoint editor indicated
by the highlighted text.
b. Call stack, while you are debugging, a window that shows a list of
procedures and functions of the caller will appear.
c. Register, displays CPU information.
d. Watch, watch window displays.
e. Output, menmpilkan program output.
f. User Screen, In general commands used to view the results of the program
we have compiled and run.
g. Evaluate / Modify, With this option you will be taken to a window with 3
box that allows you to write any change of name / expression, showed the
value of change / phrase when it's allowing you to deliver new value to
any modifiers
h. Add watch, used to add detailed data, modifiers or phrase into the watch
window.
i. Add breakpoint, add a breakpoint.

13
7. Tools
a. Messages, displays an error message window
b. Go to Next, to the next line
c. Go to previous, previous to the bari
d. Grep is used for filtering input or display rows that contain certain criteria
8. Option to set various compiler options, memory size, linker, debugger, etc.
9. Window, to set the display windows
10. Help, contains a variety of assistance provided by Turbo Pascal

C. Know the Standards Unit Turbo Pascal 7.0


The unit is a collection of constants, data types, variables, Procedure and
function. All the commands contained in turbo pascal is stored in the form of units.
Turbo pascal has provided some units include:
a. System
The unit system is the major commands in turbo pascal so we do not need to
use System Uses command at the beginning of the program. Here is an example of
the commands in the system unit.
Table 2.1 Sample Unit Command System
Command Function
INT Ignoring decimal places or round numbers
Frac Taking the decimal value of a number
Exp Looking exponentially from a number
Ln Finding Natural logarithm of a number
Pi Entering numbers Pi 3:14
Sin Looking SINUS of a number in units of radians
Cos Cos Looking cosine of a number in units of radians
Abs Looking Abs absolute (omit the negative sign) of a number
Inc Adding numbers with the number 1 or the other according to the
order number
Dec Reduce the number 1 or the other according to the order number
Odd Doing tracking whether a number is odd or not
Succ To find followers succ (successor or later) from a number or
arguments

14
Command Function
Pred To find the predecessor pred (predecessor or previous argument)
from a number or arguments
Chr command to print additional character alzim atu called ASCII
codes
Ord To locate an argument or menacri ASCII numbers of An Argument
Round round real numbers to integer
Trunc Eliminating trunc decimal of a number
Upcase Changing lowercase characters to uppercase
Lo To find the lowest byte of an argument
Hi To find the highest byte of an argument
Swap To reverse the byte swap highs and lows of an argument
Low Taking the lowest value of the range of an argument
High Taking the highest value of the range of an argument

b. Crt
Crt unit is used to manipulate text layer (windowing, laying down the screen
cursor, color for text, code and other keyboard extanded). To use the commands
contained in the unit must use Uses Crt Crt at the beginning of the program. Here
is an example command incorporated in the unit Crt.
Table 2.2 Example of Command Crt Unit
Command Function
ClrScr command to clear the screen
GoToXY To put in a certain position on the screen
TextColor To make the color of the text
TextBackGround Giving a background color to text
TextAttr TextAttr TextColor and TextBacground
Sound To mute
No Sound To stop the sound
Delay for delay time
KeyPressed To find a key has been pressed
Readkey To read the button is pressed by the user
Window To create a text window on the screen
ClrEol To remove the cursor position to the end of
the line

15
c. DOS
DOS is used when will use procedures and functions associated with the
standard DOS call, sort DetTime, setTime, DiskSize, DiskFree and others.
d. Windos
Windos is Units relating to the implementation of the operating system and
files and handle routine.
e. Graph
Graph providing a collection of sophisticated graphics routines, so can be
used for graphing purposes.
f. Graph3
Graph3 is The units are designed to support graphics applications on turbo
pascal 3.0.
g. Overlay
Overlay is The unit that contains the procedure, function and symbol for use
with Borland Pascal overlay manager.
h. Printer
Printer is a very small unit designed for use in the program printer.
i. Turbo3
Turbo3 The units were developed only to support the Turbo Pascal 3.0.

D. Creating First Program


a. Change Working Directory
Before we make a program, set the working directory we advance. Once the
editor display appears, select the File menu - Change directory then typing your
working directory and press Enter or click OK.

16
Figure 2.4 Change Working Directory
b. Writing a New Program
Sheets can be created with the new editor the following steps:
(A) Select the File menu (Alt + F)
(B) Select New sub menu that appears screen as follows:

Figure 2.5 Sheet New Editor


(C) Type in the following program:
coba_dulu program;
uses crt;
begin
clrscr;

17
write ('Program Pascalku');
readln;
end.

Figure 2.6 Code Typed Program at Sheet Editor

c. Saving Program
Program code which we type or modified would be better if directly
deposited, it is just in case if power is suddenly lost or for other reasons. How to
save the program are as follows:
(1) Select the File Menu
(2) Select Save and then give it a name and press Enter LAT1

Figure 2.7 Window for File Saving Program

18
d. Running Program
The program has been written in pascal editor can be run or executed in the
following way:
(1) Select the Run menu (Alt + R)
(2) Select RUN or command can be changed by pressing Ctrl + F9
simultaneously and press Enter to return to the Editor Pascal

Figure 2.8 The program has been executed

e. Viewing Results Program


To view the results of the program and the source code can be done
simultaneously with the following steps:
(1) Select the Debug Menu
(2) Select Output eventual output of the program and click on the area to remove
the ouput editor pascal program

19
Figure 2.9 Viewing Program Output
f. Compile Program
Before the run, the program can be compiled first to find errors that may
occur. Try removing the sign (;) at the end of the first line of the program have
been made, then do the following:
(1) Select the Compile menu (Alt + C)
(2) Select the Compile
Error message will appear as follows:

Figure 2.10 Syntax Error Program

20
Restore the program code and do it again like all the steps above so that a
dialog box that prgram is correct as follows:

Figure 2.11 The Program Compilation


The process of compiling the program can also be done by pressing Alt + F9 keys
simultaneously.
g. File Opening Program
Files that have been stored on a hard drive or other storage media can we go
back to:
(1) Select the File menu (Alt + F)
(2) Select Open (F3) then find where lkasi file storage and file names
(3) Press Enter or click Open

21
Figure 2.12 Opening Files

h. Creating File. EXE


Files. EXE or executable file is a program that can be run directly through
DOS prompt without having to open the program first Turbo Pascal. To create a
file. EXE can be done by:
(1) Select Menu Option
(2) Select the Directories, and then change the EXE directory and TPU into our
working directory and then click OK

Figure 2.13 Setting Sub Menu Directries the Option Menu

22
(3) Select Option Menu Sub Menu again and Select Save
(4) Choose Menu Compile Compile then sub menu or press Alt + F9
simultaneously
(5) Go to our working directory through Windows Explorer, the file extension will
appear. EXE that we just created

Figure 2.14 File. Exe

i. Out of Turbo Pascal


To exit the editor pascal can be done by the following:
(1) Select the File menu (Alt + F) and then select the sub-menu Exit
(2) or press Alt + X simultaneously

23
E. Exercise
1. Mention menu editor contained in Turbo Pascal 7.0
2. What is the unit and what functions Crt unit?
3. What do you know about the Unit System and why to use it does not require
command Uses (Uses System)?
4. What are the differences and Compile Run?
5. What is File. EXE and how to make it?

24
Chapter 3
Basic Pascal Programming

Basic competencies
1. Students are able to know and understand the structure of the Pascal program
2. Students are able to create a program using pascal language

A. Pascal Program Structure


Pascal language program has a composition program as follows:
Body
Declaration
Title
Complete Structure:
The program ... (Name / Title Program);
Uses ... (Name of Unit);
Labels ... (Label);
Const ... (constant);
Type ... (Type);
Var ... (Variables);
Procedure ... (Procedure);
Function ... (Function);
Begin
Statement;
End.
Minimum Structure:
Begin
Statement;
End.
Title Program
The title of the program is used as a name or a unique identifier of a program.
General Form: PROGRAM Name_Program;

25
Example: PROGRAM example 1;
Declaration
Declare an object which we will use in making a pascal program. The type
declaration is as follows:
1. Uses
Command is used to define the unit uses which we will use in making
program. The unit is a collection of constants, data types, variables,
procedures and functions. In pascal tela there are some units that are
provided include: System, Crt, Dos, Windos, Printer, Graph, Graph3,
Turbo3, Overlay, String, WinCrt.
Example: Uses Crt;
2. Label
Used when the program using goto statement to jump to a particular
statement.
Example:
Program Example_Label;
Uses Crt;
Label 10, 20, Keluar;
Begin
clrscr;
writeln(‘FKIP UNRAM’);
writeln('Mataram');
goto 20;
10:
writeln('Program Pascal');
goto Keluar;
20:
Writeln(Mari Coba Bersama');
goto 10;

26
keluar:
readln;
end.

3. Const
Const is a quantity whose value is fixed or unchanging.

Program Example_Label;
Uses Crt;
Const
NIM =’E1R007010’;
Nama=’ARINA’;
Begin
clrscr;
writeln('Nomor Induk Mahasiswa :', NIM);
writeln('Nama Mahasiswa :', Nama);
readln;
end.

4. Variable Declaration
Variable Declaration is a quantity whose value can change. Variables to
be used should be defined first.
Program Example_Variabel;
uses crt;
Var p,l,kel,luas:integer;
begin
Write('Panjang Persegi Panjang :'); readln(p);
writeln;
write('Lebar Persegi Panjang :'); readln(l);
writeln;
luas:=p*l;
kel:=2*(p+l);

27
Writeln('Luas Persegi Panjang :',luas:2);
writeln('Keliling Persegi Panjang :',kel:2);
readln;
end.
5. Type
Type is the definition of value by limiting the initial value and the final
value of the data.
Program Example_Type;
uses crt;
Type
pasaran=(Pon,Wage,Kliwon,Legi,Pahing);
Var
nama_psr:pasaran;
n:byte;
ket:string[25];
begin
clrscr;
Write('Kode Pasaran :');
readln(n);
writeln;
nama_psr:=pasaran(n-1);
case nama_psr of
Pon,Wage,Kliwon,Legi:ket:='Pasar Ramai
Pengunjung'
else
ket:='Pasar Sepi Pengunjung';
end;
write ('Hari itu :',ket);
readln;
end.

28
6. Procedure
Procedure is a separate program within a block of its own that can be
activated anywhere in the main program.
Example Procedure:

Program Example_Procedure;
Uses Crt;
Procedure Tambah (A,B:byte; Var C:integer);
begin
C:=A+B;
end;
{****** Program Utama*******}
Var hasil:integer;
begin
Tambah(4,5,hasil);
write('4',' ','+','5',' ','=',' ',hasil);
readln;
end.

7. Function
As well as procedure, function is a separate program within a block of
its own that can be activated anywhere in the main program.
Example Function :
Program Example_Function;
Uses Crt;
Function Tambah(A,B:byte):integer;
begin
Tambah:=A+B;
end;
{****** Program Utama*******}
Var hasil:integer;

29
bil1,bil2:byte;
begin
Clrscr;
write('Bilangan 1:');readln(bil1);
write('Bilangan 2:');readln(bil2);
writeln;
Hasil:=Tambah(bil1,bil2);
write(bil1,' ','+',bil2,' ','=',' ',hasil);
readln;
end.

B. HotKey
Use the buttons below to facilitate the hotkey you to operate the program as
follows:
Table 3.1 Example HotKey buttons in Turbo Pascal
Command Function
Ctrl + F9 Compile dan Run
Alt + F9 Compile
F2 Save File
F3 Open File
Alt + F3 Close Active Window
Alt + F5 OutPut
F6 Toggle Active Window
Shift + panah Blok
Ctrl + Ins Copy Blok
Shift+ Ins Paste Blok
Shift+ Del Cut Blok
Alt + Backspace Undo
Alt + X Exit from editor

C. Pascal Programming Rules


1. End of a Pascal program marked by punctuation dot (.) After the final END.

30
2. Semicolon (;) is the separator between the instructions to each other.
3. Some statements may be written into one line separated by punctuation titk
semicolon (;)
4. Is a non case sensitive or not distinguish uppercase and lowercase letters in
writing orders.
5. Example: store: = end; late: = save + start;
6. Comment lines placed between the sign (* and *) or sign between {and}
Example:
Var rerata : real; (*nilai rata-rata*)
Nil1 : real; {nilai ujian}

D. Basic Component Pascal Program


Pascal stacking pattern formed using a common programming language
components, namely:
1. Basic Symbols
Basic symbols comprising:
a. Symbol font, the letters A through Z or a through z.
b. (Uppercase and lowercase).
c. Symbol digit or digits are: 0,1,2,3,4,5,6,7,8,9.
d. Special symbols, namely: + - * /;: =, '= <><=> = <>: {} () []
2. Reserved Word (word for sure)
Reserved Word is a word that absolutely should not be interpreted other and
should be used as defined or determined by their role Pascal language.
Reserved word should not be redefined by the user, so it can not be used as an
identifier (identifier). Reserved Word This amount is different for each
language Pascal.
Examples of some reserved word that has been defined by pascal language
include:
ELSE AND LABEL SET
END OF ARRAY TYPE

31
BEGIN FUNCTION OR UNTIL
PROCEDURE FOR CASE VAR
GOTO PROGRAM WHILE CONST
IF DO WITH RECORD
Downto IN REPEAT etc.
3. Identifier (denominator)
Identifier is a word used as a name or title to something in the program. Users
can define himself a name as an identifier. This identifier consists of:
a. Identifier Standard, which is the identifier that has been defined by the
language pascal. Examples of this standard identifier such as:
ABS LN
Arctan ODB
BOOLEAN Pred
CHAR ROUND
CHR READ
COS readln
EOF SQR
EOLN SQRT
EXP succ
And much more.
b. Non Standard identifier, ie the identifier which is defined by the user pascal
language, for example;
1) the name of a program
2) the name of a constant
3) the name of a variable
4) the name of a procedure
Examples of some reserved word that has been defined by pascal language
include:
ELSE AND LABEL SET

32
END OF ARRAY TYPE
BEGIN FUNCTION OR UNTIL
PROCEDURE FOR CASE VAR
GOTO PROGRAM WHILE CONST
IF DO WITH RECORD
Downto IN REPEAT etc.
Identifier is free, but with the following provisions:
a. consists of a combination of letters and numbers with the first character
must be a letter. Uppercase and lowercase letters are considered the same.
b. Can not contain blanks.
c. Can not contain special symbols, except for the bottom line.
d. Free length, but only the first 63 characters are considered significant.
Example:
Table 3.2 Example of Giving Name Identifier
Identifier Specification
GajiKaryawan True
No_Mhs True
P3K True
1X False, the first character must be letter
A&B False, should not contain special symbols
AB False, may not contain blank
E. Pascal Programming Basic Commands
1.Writeln
Writeln is used to show the information to the screen. Writeln can also
accept arguments of type basic data (real, integer) and even string.Example:
Writeln(5.5); {real data type }
Writeln(67); {integer data type}
Writeln(false); {Boolean data type}
Writeln(‘K’); {Char data type}

33
Writeln(‘FKIP UNRAM’) {string data type}
2. Write
The function of the command with the command writeln write, write and
writeln command difference is the location of the cursor after the text
displayed on the screen or additions LF (linefeed) and CR (Carriage Return). If
you use the write command, after the text cursor will appear onscreen text
located to the right. However, writeln command will put the cursor under the
text that is displayed.
Example:
Example_Write Program;
Uses Crt;
Begin
Clrscr;
Write ('FKIP UNRAM');
Readln;
End.
Run and what happens?
Example_Writeln Program;
Uses Crt;
Begin
Clrscr;
Writeln ('FKIP UNRAM');
Readln;
End.
Run and what happens?
Both of the above program produces two different views, namely:
FKIP UNRAM _
And
FKIP UNRAM
_
Then create the following program and what are the results:??
Example_1 Program;

34
Uses Crt;
Begin
Clrscr;
Write ('Go to Napier Up Ship');
Writeln ('Be careful not pinched');
Write ('Let's Learn Pascal');
Writeln ('The word Upik It is not difficult');
Readln;
End.
3. Format write or writeln
Turbo pascal provides an easy way to format the numbers on the
display screen in accordance with the notation that we use everyday. It is very
important to clarify the outcome of a program, especially if said data type real.
To say the integer data types can be written in the format:
Writeln (data: lebar_data);
By using this format the sequence data that we want to show is displayed with
a flush right. Example:
Writeln (12356:8);
Writeln (12:8);
Writeln (1235:8);

The result:
12 356
12
1235
The same settings can also be done to the data type real. For real data types can
be formatted beikut command:
Writeln (data: lebar_data: lebar_desimal);
Example:

35
Writeln (1253.53:5:2);
Example:
1253.53
4. Gotoxy
The function of this command is to place the cursor at a specific
coordinate. Syntax: Gotoxy (column, row)
Example:
Example_2 Program;
Uses Crt;
begin
Clrscr;
gotoxy (10,10);
writeln ('Pendidikan Matematika FKIP');
end.
5. Readln
This function means asking for input values from the keyboard and
working to stop the execution of the program as long as there is no button press
ENTER.
Example:
Example_3 Program;
Uses Crt;
Var name: string [25];
begin
Clrscr;
gotoxy (25.10);
Write ('Enter your name:');
readln (name); {accept input from the user}
gotoxy (15.15);

36
Write ('Brother', '', name, '', 'You are Entering a World Without
Borders');
Gotoxy (15.17);
Write ('You're Ready???');
readln; {pause briefly to press ENTER}
end.
6. TextColor
The function of this command is to give color to the text.
Syntax: TextColor (Red), or TextColor (4);
Example_4 Program;
Uses Crt;
Var name: string [25];
begin
Clrscr;
gotoxy (25.10);
textcolor (3);
Write ('Enter your name:'); readln (name);
gotoxy (15.15);
textcolor (12);
Write ('Brother', '', name, '', 'You are Entering a World Without
Borders');
Gotoxy (15.17);
textcolor (13);
Write ('You're Ready???');
readln;
end.
Table 3.3 Color Code TextColor
Code Color Code Color
0 Black 8 Darkgray
1 Blue 9 LightBlue

37
2 Green 10 LightGreen
3 Cyan 11 LightCyan
4 Red 12 LightRed
5 Magenta 13 LightMagenta
6 Brown 14 Yellow
7 Lightgray 15 White

7. TextBackground
The function of this command is to provide the background color of a text.
Example:
Example_5 Program;
Uses Crt;
Var name: string [25];
begin
Clrscr;
gotoxy (25.10);
textcolor (13); textbackground (1);
Write ('Enter your name:'); readln (name);
gotoxy (15.15);
textcolor (12); textbackground (3);
Write ('Brother', '', name, '', 'You are Entering a World Without
Borders');
Gotoxy (15.17);
textcolor (14); textbackground (2);
Write ('You're Ready???');
readln;
end.
Table 3.4 Color Code TextBackGround
Code Color
0 Black
1 Blue

38
2 Green
3 Cyan
4 Red
5 Magenta
6 Brown
7 Lightgray

8. DelLine
DelLine is Used to delete a single line on the screen at the cursor position.
9. InsLine
InsLine is used Used to insert a blank line at the cursor position.
10. Readkey
Readkey is Used to read a character is typed, can also pause to press any
character.
11. KeyPressed
Key Pressed is Aimed to examine whether it has made an emphasis on a
certain button.
12. Sound
Sound is Aiming to create a Voice
Example:
Example_Suara Program;
Uses Crt;
Var j: integer;
begin
Clrscr;
gotoxy (25.10);
textcolor (14);
Write ('You're Ready???');
j: = 10;
textAttr: = 7;

39
textcolor (14); gotoxy (15.20);
Write ('Press Any key to exit .... ");
while not keypressed do
begin
sound (j * 10); sound (j +10 * 10);
sound (j +20 * 10), delay (30);
j: = j +10;
if j> = 300 then j: = 10;
end;
NoSound;
readln;
end.

F. Comment
Programs that we do, not just read by computers but can also be read by others.
Because of this, the clarity of the program into one thing that is important for the
program to be understood by others or programmer itself. Clarity program will
help you if one day you forget what programs mean that you created. To provide
clarity program you created, you can add comments or captions.
Feedback is an inscription on programs that do not mean anything on the
computer but it is very useful for people because it serves as documentation.
Comment in the usual pascal placed between curly braces {comment} or with a (*
Comment *).
Example:
{Pascal ------------ ------------ Writing Program}
{This program is an example of a simple pascal program}
{By:}
{NIM: E1R011004}
{Name: Farhan}

40
G. Exercises
1. How pascal language order?
2. What is the differenceabout variables and constants?
3. what is the resultsof this programs?
Try First Program;
Begin
Write ('Hello');
Readln;
End.
4. How to rule the pascal programming?
5. Indicate the location of errors following programs and repair it!

Program 1 Program 2
Program Coba Dulu; Program Coba2;
Begin Begin
Write(‘Halo’); Clrscr;
Readln; Write(‘Halo’);
End; Readln;
End;
Program 3 Program
Program Coba3; {Programpertama};
Var mod:integer; Begin;
Begin Write(‘Halo’);
Clrscr; Readln;
Write(‘angka :’,mod); End.
Readln;
End;

41
Chapter 4
Data & Type Operator

Basic competencies :
a. Students can find and use data types that exist in the programming language
pascal
b. Students can find and use the types of operators that exist in the programming
language pascal

A. Type of data provided by the PASCAL


1. Simple Data Types
Constitute the basic data types that are often used by the program include:
integer (integers), real (fractions), char (alphanumeric and punctuation), and
boolean (logical). For integer and real each divided into several categories as
follows
a. Integer numbers
Integer is an integer data type, divided into several categories as shown in
Table 1. Table 1 shows the types of data, the size and range of values in
memory. Here is a range of values of integer types:
Table 4.1 Integer Data Types
Data Type Size (in byte) Range
Byte 1 byte 0 s/d +255

Shortint 1 byte -28 s/d +127

Integer 2 bytes -32768 s/d 32767

Word 2 bytes 0 s/d 65535

Longint 4 bytes 2147483648 s/d 2147483647

b. Real numbers
Real numbers or real is a type of fractions, can be written in the
ordinary or scientific models. Examples of real numbers:

42
35.997E +11 34 265 -3.55 0.0, where E is the symbol powers of 10. So it
has a value equal to 452.13 4.5213e2. Classification of data type real
numbers are as follows:
Table 4.2 Real Data Types
Data Type Size (in byte) Range
real 6 bytes 2.9 x 10-39 s/d 1.7 x1038
single 4 bytes 1.5 x 1045 s/d 3.4 x 1038
double 8 bytes 5.0 x 10-324 s/d 1.7 x 10308
extended 10 bytes 3.4 x 10-4932 s/d 1.1 x 104932
comp 8 bytes -9.2x 1018 s/d 9.2x 1018

c. Char
This data type stores character typed from the keyboard, has 266 kinds
of tables contained in ASCII (American Standard Code for Information
Interchange). Example: 'A' 'B' '+', and so on. To remember that the writing
should be using single quotes. This data type requires a memory allocation
of 1 (one) for each byte of data.
d. Boolean Data Types
A data type logic, which contains two possible values: TRUE (true) or
FALSE (false). Turbo Pascal for Windows has three different types are:
Boolean, WordBool, and LongBool. Boolean type using the least memory,
whereas LongBool WordBool and used to write the program in accordance
with the Windows environment.
2. Structured Data Types
This type consists of: arrays, records, sets and files. String data type is an
array type, but since the string has its own uniqueness as an array of characters,
the writer needs to provide its own explanation.
a. String
String is an array that holds the data (array), for example 'ABCDEF' is a
constant string that contains 6 bytes of characters. The size for this data
type is 2 s / d 256 bytes, the number of elements 1 s / d 255. String

43
declared with string [constant] or string. When the size of the string is not
defined then it will consume a lot of space, because the size of the string to
adjust the default. Suppose var word: string [20], or var word: string,
because a string is an array of characters. Then said [1] is the first character
of the string, then said [2], is the second element, and so on.
Routines in Pascal for string manipulation:
1) Length: length of the string produces. Syntax: length (s) Example: n: =
length (s), eg s: = 'programming', n will be equal to 11.
2) Copy: copy an extract characters from a string. Syntax: copy (s, from,
amount) Example: st: = copy (s, 5,3); extract 3 characters of s, starting at
the fifth character. Suppose s: = 'Who are you?'; St is 'are'. note: if the
index more bear than the length of the string then the result will be empty:
Example: st: = copy (s, 15.4); {blank} if the number of strings to be
extracted is greater than s, then the result is the remaining part of the string
. Example: st: = copy (s, 9.10); st result is 'you?'
3) Post: generate position of a substring from a string. Syntax: Posts (substr,
s) Example: n: = pos ('are', 'Who are you?') {N: = 5;} If the substring is not
found, then the result is 0.
4) Val: convert string to numeric. Syntax: val (strvar, numvar, errorcode)
5) strvar: is a variable string to be converted, numvar numeric variable (can
be integer or real, and the errorcode is an integer variable that stores the
error code (error code). If the errorcode is 0, the conversion succeeded.
Instead, it will indicate the position where the strvar that caused the failure.
6) Str: convert numeric to string. Syntax: str (numvar, strvar)
7) Concat: Combining two or more strings. Syntax: concat (s1, s2, ..., sn)
8) Insert: Inserts a string into another string. Syntax: insert (origin, target,
index)
9) Delete: delete n characters from the string s starting from index i. Syntax:
delete (s, i, n);

44
10) Fillchar: string s filled with character c to s equal to n-1 characters long.
Syntax: fillchar (s, n, c); Beware: s [0] , do not forget to add s [0]: = chr (n-
1); to normally.
b. Subrange
It is a range that shows the value of the smallest and largest value that will
be used. Declaration subrange is Type.
c. Enumerated
Or scalar data types showed a collection of the value of the order is certain.
Declared value of the type will be represented by identifier-identifier that
will be a constant value.
d. File Type
File or file is a collection of a number of components that same data type,
the amount is not specified and is usually stored in external storage.
e. Pointer Types
Pointer is a special variable that contains an address (addresses) in other
locations in the memory. A variable points (points) to something that is
called a pointer.

B. Operator
Operators in pascal grouped into:
1. Arithmetic
Table 4.3 Arithmetic Operators
Operator Operation Operand Type Study Results of
Operations
+ Addition Integer, real Integer, real
- Reduction Integer, real Integer, real
* Multiplication Integer, real Integer, real
/ Division Integer, real Integer, real
div integer division integer, integer
integer
mod The rest of the mod integer, integer
integer division integer

45
2. Boolean
Table 4.4 Boolean Operators
Operator Operation Operand Type Type Study Results of Operations
not negation boolean boolean
and logic ‘and’ boolean boolean
or logic ‘or’ boolean boolean
xor logic ‘xor’ boolean boolean

3. Relational
Table 4.5 Relational Operators
Type Study Results
Operator Operation Operand Type
of Operations
simple type, string, pointer
= Equal boolean
and set
simple type, string, pointer
<> Not equal boolean
and set
< Smaller than simple type, string boolean
> Greater than simple type, string boolean
Less than or
<= simple type, string boolean
=
Greater than
>= simple type, string boolean
or =

4. Set
Table 4.6 Operator Set
Operator Operation Operand Type Results
= Equal Set, set boolean
<> Not equal Set, set boolean
<= Less than or = Set, set boolean
>= Greater than or = Set, set boolean

5. Mathematical Functions in Standard Pascal


Table 4.7 Standard Mathematical Functions
Function Description Argument Type Operating
Name Type Results
abs absolute value real/integer real/integer

46
arctan arctan (radian) real/integer real
cos cosine (radian) real/integer real
sin sin (radian) real/integer real
exp function powers of e real/integer real
ln Ln real/integer real
round round nearest integer real integer
sqr squared real real/integer real/integer
sqrt The square root sqrt real real/integer real
trunc Rounding trunc down real real/integer integer

6. Symbols Who Have Special Meaning


Table 4.8 Symbols that have special meaning

Symbol Description and Examples


Assign Value (stocked)
Example :
:=
Gol:=’A’;
gaji_pokok:=2500000;
Equal to
= Example:
if gol = ‘A’ then gaji_pokok:=2500000;
Defines a name
: Example:
Var A: char;
The end of a sentence (statement)
Example:
;
Writeln(‘FKIP UNIVERSITAS
MATARAM);
The end of a program
. Example:
End.

47
C. Exercise

1. Consider the following program and what are the results? why? :
Program luas_segitiga;
Uses crt;
Var alas,tinggi,luas : integer;
Begin
Clrscr;
alas:=5;
tinggi:=7;
luas:=0.5*alas*tinggi;
write(‘Luas :’,luas);
readln;
end.

2. Write the following expression using pascal language:


a. 𝑦 = 𝑚𝑥 + 𝑐
b. 𝑦 = 𝑥 2 + 3𝑥 + 3
c. 𝑦 = 𝑚𝑐 2
d. 𝑐 = √𝑎2 + 𝑏 2
3. Create a program to calculate the area and circumference Circle
4. Create a program to display the results of arithmetic operations of two positive
numbers. Here is an example of a desirable when inserted two numbers are 15
and 4.
Enter Numbers to-1: 15
Enter the Numbers 2: 4
Results of Operations
***********************
15 + 4 = 19
15-4 = 11

48
15 * 4 = 60
15 Div 4 = 3
15 Mod 4 = 3
5. Create a program to calculate the temperature conversion from Celsius to
Reamur, Fahrenheit and Kelvin.
Celsius: 100 (input)
Reamur: 80
Fahrenheit: 212
Kelvin: 373
6. Create a program to convert the value into a number Kilogram (kg), ounces
and grams. Suppose we enter the number 1550 numbers will be converted into
1 kg 5 ounces 50 grams

49
Chapter 5
Selection And Iteration Statements

Basic Competencies
1. Students are able to understand Selection and iteration Statements
2. Students are able to solve mathematical problems by using selection and iteration
statements.

In Pascal there are two control structures used to handle conditions and their resultant
decisions : the binary construct IF-THEN ELSE and the multiple choice construct CASE.

A. Selection Statements
1. If then statement
a. The Simple Decision Of IF-THEN Statement
The IF-THEN statement takes the general form:
IF condition THEN
statement;
The statement starts with the keyword IF, followed by a Boolean expression,
followed by the keyword THEN, followed by result to be executed if the
condition is true. To express a simple condition you can use the IF-THEN
statement, as in the following example:
{--------------------------------------------Example 5.1---------------------------}
Program Lulus1;
Uses wincrt;
Var Nilai : integer;
Begin
Write ('Masukkan Nilai Anda : ');
Readln (nilai);
If nilai > 45 Then
Writeln('Anda Lulus');
End.

50
{--------------------------------------------------------------------------------------------}
As you can see, the IF construct is one statement ending with semicolon. If the
value of variable nilai is more than 60, the part after keyword THEN is
executed, otherwise the whole statement is skipped and the program execution
resumes its original flow at the next statement.
Sample Run
Masukkan Nilai Anda : 60
Anda Lulus
b. The IF-THEN-ELSE construct
The complete IF statement includes the two cases that result the from testing
the condition. It takes the form
IF condition THEN
Statement
ELSE
Statement;
Here is the example:
{--------------------------------------------Example 5.2-------------------------------}
Program Lulus2;
Uses wincrt;
Var Nilai : integer;
Begin
Write ('Masukkan Nilai Anda :');
Readln (nilai); {Input data}
If nilai >45 Then {selectionthe variable condition}
Writeln('Anda Lulus');
Else
Writeln('Anda Tidak Lulus');
End.
{-----------------------------------------------------------------------------------------}

51
If you add another statement to either of two cases you have to use BEGIN-
END blocks. The new construct will look like this:
{--------------------------------------------Example 5.3-----------------------------}
Program Lulus3;
Uses wincrt;
Var Nilai : integer;
Begin
Write ('Masukkan Nilai Anda :');
Readln (nilai);
If nilai >45 Then
begin
Writeln('Anda Lulus');
Writeln(‘Selamat Atas Keberhasilan yang Anda Raih’);
end
Else
begin
Writeln('Anda Tidak Lulus');
Writeln (‘Terus Berusaha Masih Ada Kesempatan’);
End;
Readln;
End.
{---------------------------------------------------------------------------------------}
C. The ELSE-IF Ladder
Although the IF-THEN-ELSE statement is intended for binary choice, it can be
extended to handle more complicated causes. This news arrangement of the
construct which is sometimes referred to as the IF-ELSE Ladder:
IF condition-1 THEN
Statement-1
ELSE IF condition-2 THEN
Statement-2

52
ELSE IF condition-3 THEN
Statement-3
...
ELSE
Statement-n;
Here is the example:
{--------------------------------------------Example 5.4------------------------------}
Program Lulus4;
Uses wincrt;
Var Nilai : integer;
Begin
Write ('Masukkan Nilai Anda : ');Readln (nilai);
If Nilai >= 80 Then
Begin Writeln('Anda Mendapat Nilai A');
end
Else
If (Nilai >= 65) and (Nilai< 80) Then
Begin Writeln('Anda Mendapat Nilai B');
end
Else
If (Nilai >= 50) and (Nilai < 65) Then
Begin Writeln('Anda Mendapat Nilai C');
End
Else
If (Nilai >=40 ) and (Nilai < 50) Then
Begin Writeln('Anda Mendapat Nilai D');
End
Else
begin
Writeln('Anda Tidak Lulus Dengan Nilai E');

53
Writeln ('Terus Berusaha Masih Ada Kesempatan');
End;
Readln;
End.
{-------------------------------------------------------------------------------------------}

d. Nested Conditions
The IF-THEN-ELSE constructs can be nested inside each other, as in the
following form:
IF condition-1 THEN
IF condition-2 THEN
IF condition-3 THEN
...
IF condition-n THEN
Statement-n1
ELSE
Statement-n2
...
ELSE
Statement-2
ELSE
Statement-1;

Here is the example:


{--------------------------------------------Example 5.5-------------------------------}
Program Lulus5;
Uses wincrt;
Var Nilai : integer;
Begin
Write ('Masukkan Nilai Anda : ');
Readln (nilai);

54
If Nilai > 40 Then
If Nilai > 60 Then
If Nilai > 70 Then
If Nilai > 80 Then
Writeln('Anda Mendapat Nilai A')
Else
Writeln('Anda Mendapat Nilai B')
Else
Writeln('Anda Mendapat Nilai C')
Else
Writeln('Anda Mendapat Nilai D')
Else Writeln ('Anda mendapat nilai E');
Readln;
End.
{---------------------------------------------------------------------------------------}
2. The Multiple Choice: CASE

The case contruct is used to deal multiple alternatives, such as the user
menu options. It takes the general of:
CASE Expression OF
Label-1: Statement-1;
Label-2: Statement-2;
...
Label-n: Statement-n;
End
Or
CASE Expression OF
Label-1: Statement-1;
Label-2: Statement-2;
...

55
Label-n: Statement-n;
Else
Statement
End
The case expression, also called is selector. Look at this example:
{--------------------------------------------Example 5.6---------------------}
Program luas1;
Uses Wincrt;
var luas,keliling,sisi,pilih : integer;
Begin
Writeln('1. Luas Persegi 2. Keliling Persegi');
WRITE('PILIHAN ANDA ');
Readln(Pilih);
Case Pilih of
1: begin
WRITE('MASUKKAN SISI PERSEGI ');
readln(sisi);
luas:=sisi*sisi;
writeln('Luas Persegi Panjang dengan PANJANG sisi ',sisi,' adalah
',luas);
end;
2: begin
WRITE('MASUKKAN SISI PERSEGI ');
readln(sisi);
keliling:=4*sisi;
writeln('Keliling Persegi Panjang dengan sisi ',sisi,' adalah ',keliling);
end;
end;
readln;

56
end.
{---------------------------------------------------------------------------------}

B. Iteration Statements
Iteration is repeated process. Iteration always exist in programming
language. Pascal ready-made control structures we can void such messy code.
A control structure contains both the branching statement and the condition in
one construct. In Pascal there are three loops structures you are introduced to
the following construct : the FOR loop, the WHILE loop and The REPEAT
loop. Each the three loops has different features that suit different application.
a. The For Loop
The for loop construct is accounted loop used to repeat a statement or a
block of statements a specified number of times. It includes the initializiation
of the counter, the condition and the increment.
Look at this example:
{----------------------------------------Example 5.7---------------------------}

program for_1;

uses wincrt;

var i : integer;

begin

for i:= 1 to 5 do

writeln('Program Studi Pendidikan Matematika FKIP UNRAM');

end.

{-------------------------------------------------------------------------------}
This programs gives the same results as the previous program does but
it simpler. The for loop does the some work done in the provious program. It
assigns the control variable i the initial value 1, then executes the statement,
increments the control variable by one, and repeats the process until the value

57
of the i reaches the final value of 5. The general form of the For construct is
as follows:
FOR control-variable:= expression-1 TO expression-2 DO statement;

Where:

Control variable is the loop counter,

Expression-1 is the initial value,

Expression-2 is the final value.

As usual you can include as many statements as you want inside the loop by
using the BEGIN-END blocks. Now, can you explain the different about the
example :

{--------------------------------------------------Example 5.8-------------------------}

Program for2;
uses wincrt;
var i,j:integer;
begin
j:=0;
clrscr;
for i:= 1 to 10 do
j:= j+3;

{--------------------------------------------------Example 5.9-------------------------}

Program for3;
uses wincrt;
var i,j:integer;
j:=0;
clrscr;
for i:= 1 to 10 do
begin
j:= j+3;

58
write (j, '');
end;
readln;
end.
{----------------------------------------------------------------------------------------------}

In the previous examples, the For loop counter was always


incremented. That means the final value of counter must be greater than the
initial value, or else the loop will never be executed.
By using an alternative form of the for loop and replacing the keyword
TO with the key word DOWN TO as in the following form:
FOR control-variable:= expression-1 DOWNTO expression-2 DO
statement;

{------------------------------------------------Example 5.10-------------------------}

Program faktorial;
var counter, nilai: integer;
faktorial:real;
begin
write (' Masukkan nilai faktorial yang anda inginkan: ');
readln(nilai)
faktorial:=1;
for counter:= nilai downto 1 do
faktorial:=faktorial*counter;
writeln('Faktorial dari ', nilai, ' adalah ', faktorial:0:0);
writeln;
end.
{----------------------------------------------------------------------------------------------}

b. Nested Loops

59
The for loop stataement can be used inside another loop, like any other
statement. You can nest as many loops as you wish inside one another,
according to your application. The next program displays on your screen the
following array of numbers.
1 1 1

1 2 2

1 3 3

2 1 2

2 2 4

2 3 6

The array consist of six row and three coloumn. You can control the number of
row and coloumns by using the counters of two nested loops. Look at this
example:

{--------------------------------------------------Example 5.11------------------------}

program nestedloop;
uses wincrt;
var i,j,k:integer;
begin
for i:=1 to 2 do
begin
for j:= 1 to 3 do
begin
k:=i*j;
writeln(i,' ',j,' ',k);
end;
end;
readln;
end.

60
{----------------------------------------------------------------------------------------------}

c. The While Loop

The While loop construct contains the necessary condition to terminate the loop, but
unlike the FOR loop, no counter is included. It takes the general form:

WHILE condition do

Statement;

This form simple says: “Execute the following statement as long as the condition is
TRUE”

Look this example:

{--------------------------------------Example 5.12.-----------------------------}

program while1;
uses wincrt;
var i,h,a:integer;
begin
i:=1;
a:=5;
while a < 8 do
begin
h:=h+a;
i:=i+a;
inc(a);
writeln(h);
writeln(a);
end;
readln;
end.
{----------------------------------------------------------------------------------------------}

61
d. The REPEAT Loop

This loop is used to execute a group of statements until a specified condition is


met. It takes the form

REPEAT
Statement-1;
Statement-2;
Statement-3;
...
Statement-n;
UNTIL condition

Look at this example:


{-------------------------------------Example 5.13 -------------------------------------}
program repeat1;

uses wincrt;

const

phi=3.14159;

var

luas, keliling, jari2: Real;

pilih: Char;

begin

clrscr;

writeln('----------------------------------------------');

writeln('Program Menghitung Luas dan Keliling Lingkaran');

writeln('----------------------------------------------');

repeat

write('Masukkan Jari-jari Lingkaran (cm) : ');

62
readln(jari2);

luas := phi * sqr (jari2);

writeln('Luas Lingkaran adalah : ',luas:2:2,' cm2');

keliling := 2 * phi * jari2;

writeln('Keliling Lingkaran adalah : ',keliling:2:2,' cm');writeln;

writeln('Tekan ENTER Untuk melanjutkan'); readln;

writeln;

writeln('Apakah ANDA Ingin Mengulang dengan Jari2 yang berbeda?


(Y/T)');readln(pilih);

until (pilih = 't') or (pilih = 'T');

end.

{-------------------------------------------------------------------------------------------}

C. Exercises
1. What is the output for each of the following WRITELN statements:
a. Writeln (300 > 4);
b. Writeln (300 < 200) or (300 > 100);
c. Writeln (TRUE or FALSE);
d. Writeln (TRUE and FALSE);
2. Describe the function of the following case statement:
CASE Grade percentage DIV 10 of
9, 10 : Writeln (‘Distinct’);
8 : Writeln (‘Very good’);
7 : Writeln (‘Good’);
5, 6 : Writeln (‘Passed’);

0,1,2,3,4 : Writeln (‘Failed’);

63
End;

What is the massage displayed when you input each of the following
grades?

a. 84
b. 63
c. 52
d. 33
e. 99
3. Write a Pascal Program to read Pascal threeangle!
4. Write a Pascal Program a simple calculator!
5. Write a Pascal program to print the even numbers from 1 to 100.

64
Chapter 6
Procedures And Function

Basic Competencies
1. Students are able to understand procedures and Function
2. Students are able to solve mathematical problems by using procedures and
Function

When you deal with real applications the problem get more complex
than those you have met so far, so you usually have to break the main problem
down into simpler tasks and program each individually in a subprogram. The
subprograms are then combined together to build up the complete program. If
you can break your application down into the smallest possible modules, you
will find that many of them are common problems such as sorting names or
numbers. This means that you can write some generic subprograms dan use
them later in different applications. In Pascal you can divide your program into
smaller subprograms called procedure and function. Actually the Pascal
language itself is made up of predefined procedures and function.

A. Procedure
A procedure definition is very similar to a program definition in th
consist of a header, a declaration part, and statements. Let us begin with
simple procedure to draw a line 40 characters long.
{----------------------------------Example 6.1--------------------------------}

Program Procedure1;
uses wincrt;
{-----------------------Beginning of Procedure----------------------------}

procedure drawline;
const dash = '-';
length = 40;

65
var i:integer;
begin
for i:=1 to length do
write(dash);
writeln;
end;
{----------------------------End of procedure---------------------------------}

{---------------------------Main Program--------------------------------------}

begin
writeln;
drawline;
writeln(' ** Ini adalah contoh prosedur ** ');
drawline;
End.
{------------------------------------------------------------------------------}

1. Passing Parameters to Procedures


The procedure drawline is used to draw a line specifis
length(40), which may not be useful for any other application. In the
following program the example procedure is modified with one
parameter:
{------------------------------Example 6.2---------------------------------}

program Luaslingkaran_parameter;

uses wincrt;

var luas:real;

jari2:byte;

procedure Luas_lingkaran(r:integer; var l:real);

66
begin

l:=pi*r*r;

end;

{----------------------Main Program--------------------}

begin

clrscr;

write('Masukkan jari-jari lingkaran : ');readln(jari2);

Luas_lingkaran(jari2,luas);

writeln;

write('Luas Lingkaran dengan jari-jari',jari2,' adalah :',' ',luas:3:2);

readln;

end.

{--------------------------------------------------------------------------------}

When a value is used as a parameter, it is said that the


parameter is passed by value; if the parameter is a variable, it is said to
be passed by reference. When formal parameters are preceded by the
word var they are called variable parameters; otherwise they are value
parameters. In above example r is value parameter and l is reference
parameter.
The general form of the procedure header is:
PROCEDURE name;
Or
PROCEDURE procedure-name(formal-parameter-list);
The general form of the procedure call is:
procedure name;
Or

67
procedure-name(actual-parameter-list);
The following program is an example of using both types of formal
parameters. It demonstrates the same logic as in Example 6.2 does but
uses a procedure.

B. Function

A function is a subprogram that returns a value, which is then


assigned to the functionname in the calling program. Like predefined
functions, user defined functions have one or more parameters. The
function definition comes in the subprogram section of the declaration
part and includes a header, a declaration part, and statements.
The function header takes the following form:
FUNCTIONfunction-name(formal-parameter-
list):return-type;
Like procedures, function are independent sub programs. All
parameters, variables, and constant declared within the function body
are local and are visible to it and other program units. In a function
subprogram, the function must be assigned a value.

Application : The Fibonacci Sequence


A Fibonacci sequence is the sequence of numbers 1, 1, 2, 3, 5, 8, . . ., in
which each successive number is equal to the sum of the two preceding
numbers. The following example reads the number of elements and
displays the Fibonacci sequence up to this number.
{---------------------------------xample 6.3---------------------------------}

program deret_fibonacci;
uses wincrt;
const TAB = CHR(9);

68
var i,n:integer;
function Fibonacci(I:Integer):Longint;
begin
If i<= 1 then
Fibonacci :=1
else
Fibonacci := Fibonacci(i-1)+Fibonacci(i-2)
end;
begin
write('Anda mencari suku ke: ');readln(n);
writeln('Number', TAB, ' Fibonacci Number');
i:=0;
While i< n do
begin
writeln(i:2, TAB ,Fibonacci(i):15);
i:=i+1;
end;
writeln;
writeln('Press Enter To continue...');
readln;
end.
{------------------------------------------------------------------------------}

C. Recursive Function and Procedure


A Function or procedure may call itself, a property called
recursion. The factorial function is a good example of recursion.
Youknow that the factorial of a number X can be obtained from the
relation:
Factorial(x) = x *faxtorial (x-1)

69
In other words, to get the factorial of 4 you multiply 4 by the factorial
of 3; to get the factorial 3 you multiply by the factorial of 2, etc. This
continues until you reach the value 1. Here is the program that contains
the factorial function.
{---------------------------Example 6.4 --------------------------------------}
program rekursi1;
uses wincrt;
var nilai,X:integer;
Function Faktorial(X:INTEGER):REAL;
begin
if x<= 1 then
faktorial:=1
else
faktorial:= X*faktorial(X-1);
end;
begin
write('masukkan nilai yang akan di cari faktorialnya: ');
readln(nilai);
writeln('faktorial dari ' ,nilai,' adalah ' ,faktorial(NILAI):0:0);
end.
{----------------------------------------------------------}

D. Exercise
1. Write the prime numbers procedure.
2. Write afunction to calculate and return the average of three real
numbers.
3. Write a function to return the maximum number in one dimensional
array and include the function in a program.

70
4. Write a pascal program to print:
****************AYO BELAJAR LUAS BANGUN DATAR*******************
1. Luas persegi panjang
2. Luas Persegi
3. Luas SegiTiga
4. Luas Lingkaran
5. Luas Trapesium
6. Luas Jajarangenjang
7. Luas Belah Ketupat
8. Luas Layang-layang
9. Keluar Program
10. Tentukan Pilihan[1/2/3/4/5/6/7/8/9]:

Chapter 7
Arrays and Records

Basic Competencies

71
1. Students are able to understand Array And Records
2. Students are able to solve mathematical problems by using Array and
Records

In Pascal, the structured data types are divided into the following categories :
Structured types:
 Arrays
 Records
 Sets
 Files:
 Predifined : TEXT files
 User-defined : non TEXT files
In this chapter, you will cover Arrays And Records. The file type and its application
are explained in chapter 8.
A. Arrays
If you would like to imagine the case if you are dealing with class of one
hundred students. It would be almost imposibble to use one hundres variables to store
names. The practical way to store this kind of data is to use the array data structure,
which is useful for storing a collection of related data items. In the case of the
students you would need to declare one subscripted variable, and you would represent
your data like this:
Student [1]
Student [2]
Student [3]
...
The name of te variable is student and the number between the bracket is called
subscript or index. Changing the index gives you a new memory location in which
to store a new name. This type of data structure is called a one-dimensional array.

72
It is useful to represent data such as names of group of people, scores of one
student in several classes, or any similira set of related items.
In this chapter you met a special type of one –dimensional array, which used to
store a string of text in standard Pascal, and you already know that each element in
this array is referred to by a number.
In other application you may need a two dimensional array, which is capable
of handling more complicated structures. For example, suppose that you want to
store of a group of students in different classes. In mathematics, a one-dimensional
array is called a vector, while a two dimensional array is called a matrix. You may
come across these names in mathematical applications.
1. One-Dimensional Array
A one dimensional array is declared using the following form:
VAR
Array-name:ARRAY[index-range] OF element type:
If you want for example, to declare an arrays to store test scores of ten students
as real numbers, you can declare your array like this:
VAR
Score: ARRAY[1..10] OF REAL;
This array can hold up to ten real numbers. The index range [1…10] indicates
that the indexes of the array elements start from 1 and end at 10. The index
range, which is a subrange can be of any ordinal type but the array elements
can be of any data type.
`Look at this program of the array:

{--------------------------------------Example 7.1--------------------------------------}

Program BilanganPrima_Array;
Uses winCrt;

73
Var
Prima : Array[1..100] of Integer;
i,j : Integer;
n : integer;
bil : Integer;
Begin
ClrScr;
Write('Untuk menentukan bilangan prima antara 1-100,masukkan
rentang nilai yang dinginkan : ');
readln(n);
For i := 2 to n Do
Begin
Prima[i]:=i;
For j:= 2 to i-1 Do
Begin
bil := (i mod j);
If bil = 0 then Prima[i]:=0;
End;
If Prima[i]<> 0 Then Write(Prima[i],' ');
End;
Readln;
End.
{-------------------------------------------------------------------------------------------}
Declaration of Arrays in The Type Section
It is preferable that array declarations be associated with type statement,
as in this example:
TYPE
AnArray= ARRAY[1..6] OF INTEGER;
VAR

74
MyArray:AnArray;
2. Two-Dimensional Array
A two dimensional array is declared using the following form:
VAR
Array-name : ARRAY[index-range-1, index-range-2] OF element-type:
You may also declare it in the the type section as follows:
TYPE
Type-name = ARRAY[index-range-1, index-range-2] OF element-type:
where index-range-1 and index-range-2 are the ranges of the first and second
dimensions.
Look at this program of the array:

{--------------------------------------Example 7.2--------------------------------------}

Program matriks;
uses wincrt;
type data = array[1..10,1..10] of integer;
var matrikI,matrikII : data;
baris,kolom,pil : integer;
procedure isimatrik;
var i,j : integer;
begin
clrscr;
writeln('Penentuan ORDO MATRIK I');
write('Masukan banyak baris matrik I = ');readln(baris);
write('Masukan banyak kolom matrik I = ');readln(kolom);
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);

75
readln(matrikI[i,j]);
end;
clrscr;
writeln('Penentuan ORDO MATRIK II');
write('Masukan banyak baris matrik II = ');readln(baris);
write('Masukan banyak kolom matrik II = ');readln(kolom);
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
readln(matrikII[i,j]);
end;
end;
procedure jumlahmatrik(m1,m2 : data);
var hasil : data;
i,j : integer;
begin
for i:=1 to baris do
for j:=1 to kolom do
begin
hasil[i,j]:=m1[i,j]+m2[i,j];
end;
clrscr;
writeln('Hasil Penjumlahan MATRIK');
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);readln;
write(hasil[i,j], ' ');readln;

76
end;
end;
procedure kurangmatrik(m1,m2 : data);
var hasil : data;
i,j : integer;
begin
for i:=1 to baris do
for j:=1 to kolom do
begin
hasil[i,j]:=m1[i,j]-m2[i,j];
end;
clrscr;
writeln('Hasil Pengurangan MATRIK');
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);readln;
write(hasil[i,j], ' ');readln;
end;
end;
procedure kalimatrik(m1,m2 : data);
var hasil : data;
i,j,z : integer;
begin
for i:=1 to baris do
for j:=1 to kolom do
begin
hasil[i,j]:=0;
for z:=1 to baris do

77
hasil[i,j]:=hasil[i,j]+m1[i,z]*m2[z,j];
end;
clrscr;
writeln('Hasil Perkalian MATRIK');
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);readln;
write(hasil[i,j], ' ');readln;
end;
end;
begin
writeln(' M E N U');
writeln('(1) Penjumlahan Matrik');
writeln('(2) Pengurangan Matrik');
writeln('(3) Perkalian Matrik');
write('Pilihan = ');readln(pil);
clrscr;
case pil of
1 : begin
isimatrik;
jumlahmatrik(matrikI,matrikII);readln;
end;
2 : begin
isimatrik;
kurangmatrik(matrikI,matrikII);readln;
end;
3 : begin
isimatrik;

78
kalimatrik(matrikI,matrikII);readln;
end;
end;
end.
{-------------------------------------------------------------------------------------------}
3. Multidimensional Array
A multidimensional array is declared using the general form:
TYPE
Type-name = ARRAY[index-range-1, index-range-2,
. . ., index-range-n] OF element-type:
In most applications, however, you will not need more than two dimensions.

B. Records
A Record, another structure type in Pascal, is a collection of related
data items, which may be of different types. Each it in the record is called a
field. Take a look at this record, which is used to store information about
each employee in a company.
Employee Record
Field Information Possible Data Type
1 Name String
2 Adress String
3 Phone Number String/Integer
4 Marital Status Char/Enumeration
The declaration of record takes the form
Type-identifier = RECORD
Field-list
End;

79
The field list contais the name and type of each field as in this declaration
of the record employeerecord.
TYPE
Employeerecord = RECORD
Name :STRING[25];
Address :STRING[40];
Phone : STRING[12];
MaritalStatus : CHAR;
END;
Look at this example:
{------------------------------------Example 7.3--------------------------------------}
Program Data_Mahasiswa;
Uses Crt;
Type mahasiswa=record
nim:string[9];
nama:string[15];
n1,n2,n3:integer;
end;
Var a :mahasiswa;
total:real;
huruf:char;
ket :string[20];
pre :string[20];
keterangan:string[100];
pilih:char;
Begin
ClrScr;
textcolor(14);
repeat

80
write('NIM :');readln(a.nim);
write('Nama :');readln(a.nama);
write('Nilai Tugas:');readln(a.n1);
write('Nilai UTS:');readln(a.n2);
write('Nilai UAS:');readln(a.n3);
total:=(2*a.n1+3*a.n2+5*a.n3)/10;
if ((total >= 0) and (total<= 40)) then
begin
huruf:='E';
ket :='Sangat Tidak Baik';
pre :='TIDAK LULUS';
end;
if ((total > 40) and (total<= 60)) then
begin
huruf:='D';
ket :='Tidak Baik';
pre :='TIDAK LULUS';
end;
if ((total > 60) and (total<= 75)) then
begin
huruf:='C';
ket :='Baik';
pre :='LULUS';
end;
if ((total > 75) and (total<= 85)) then
begin
huruf:='B';
ket :='Sangat Baik';
pre :='LULUS';

81
end;
if ((total > 85) and (total<= 100)) then
begin
huruf:='A';
ket :='Sangat Baik Sekali';
pre :='LULUS';
end;
writeln;
if (copy(a.nim,3,1)='R') then
begin
keterangan:='Pend.Matematika';
end;
if (copy(a.nim,3,1)='M') then
begin
keterangan:='Pend.Kimia';
end;
if (copy(a.nim,3,1)='Q') then
begin
keterangan:='Pend.Fisika';
end;
if (copy(a.nim,3,1)='A') then
begin
keterangan:='Pend.Biologi';
end;
writeln;
Clrscr;
textcolor(11);
writeln('Data Mahasiswa');
writeln('NIM :',' ',a.nim);

82
writeln('Nama Mahasiswa :',' ',a.nama);
writeln('Prodi :',' ',keterangan);
writeln('Nilai Tugas :',' ',a.n1);
writeln('Nilai UTS :',' ',a.n2);
writeln('Nilai UAS :',' ',a.n3);
writeln('Nilai Total :',' ',total:3:2);
writeln('Nilai Huruf :',' ',huruf);
writeln('Keterangan :',' ',ket);
writeln('Predikat :',' ',pre);
readln;
writeln('Mau coba lagi? Y/T');readln(pilih);
until (pilih='t') or (pilih='T');
end.
{--------------------------------------------------------------}

C. Exercise
1. Determine wether or not the following TYPE section declaration
are valid:
TYPE
{a} Size = 1. .100 div 2;
{b} Size1 = 1..200;
{c} Size2 = 1..100/2;
{d} int = integer;
2. Write a Pascal program to read and store the test scores of five
students, then display the output as shown below:
Student Score
----------------------------
1 90
2 88

83
3 91
4 78
5 75
-----------------------------------------
Average score = 84,40
The best score = 90
3. If you have the following declaration in your program
VAR Day (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
Determine wether or not the following CASE statement is valid:
CASE Day OF
Mon . . Fri:
Writeln(‘Working Day’);
Sat . . Sun:
Writeln(‘Weekenday’);
End;

Chapter 8
Data Files

Basic Competencies

1. Students are able to understand Data Files and solve mathematical


problem by using Data Files.

A. The File Type

A FILE (which is a structured type) is generally defined as acollection


of related items stored on disk or any other external storage medium and
arranged in sequence as shown in the following figure.
Item-1 Item-2 Item-3 Item-4 ... EOF

84
A file item (also called a file component or file element) may be of any simple
or structured type except the type FILE.
Files may be accessed to perform either one of the following operations:
 Reading from a file (input)
 Writing to a file (output)
Files can be organized as either sequential acces files or random acces files. In
the first method no item in the file can be reached unless all the preceding items
are read. One example of a sequential acces files is a purchase list which has to be
read from the top down to access a specific item. The random access file is
organized like a set of post office boxes, which are identified by numbers and
accessed direcly witout the need to go through them all.
While standard Pascal allows only sequential access files, many
implementation of Pascal provide random acces files as well. The files discussed
in this chapter are all sequential access files.

B. Text Files
Standard Pascal provides two types of files, TEXT files and non TEXT
files (also called binary or typed files).
A Text file is the simpler file structure as its element are call characters.
You have already used the standard input file and the standard output file
which are classified as text files. A text file consist of successive lines of
characters separated by end-of-line marks and ends with the end-of-file mark,
as in the example :
This is a text file. (EOLN)
Each line is composed of successive characters. (EOLN)
Lines are separated by end-of-line marks. (EOLN)
The file is terminated by end-of-file mark. (EOLN)

85
on the disk looks exactly the ame as the file you type onto the screen
from the keyboard. The characters in a text files are stored in the ASCII format
(or EBCDIC in some systems), which means that if the file contains a number
like 1234 it will be stored in four bytes, each byte representing the ASCII code
of digit. This is not the case if the numbers is treated as an integer, in which
case it is stored in the internal binary format (0000010011010010) in two
bytes.
As we discuss these change, you will learn the protocols necessary to
retrieve information from a text file.
The File Variable
In order to use a disk text file, you have to declare a file variable of the
type text. If you choose a name like diskfile for this purpose, the declaration
will be:
VAR
DISKfile : Text;

File Parameters
To use a file in standard Pascal, you must include the file variable
among the other file parameters in the program header (this is not necessary in
oyher implementations)
Program TextAnalyzer2(OUTPUT, Diskfile);

Here are some commands which are used to open the files :

Commands Meaning Syntax


Assign Linking file variable to Assign
file name (txtfile,’Contoh.txt’);
Rewrite To write one or more Rewrite(txtfile);
items to a file
Append Use to open the files in Append(txtfile);
new output
Reset Opening a file for input Reset(txtfile);

86
Read To read the file Read(txtfile)
Close Closing the file Close(txtfile);
EOF (end of file) EOF(txtfile);
EOFLn (end of Line) EOFLn (txtfile);

C. Displaying Text Files


Look at this example about the text files
{------------------------------------------------Example 8.1---------------------------------------------}

Program bacafile;
uses wincrt;
var fileku: text;
nama : string;
s : string;
begin
clrscr;
write('Nama File yang akan di baca : ');
readln(nama);
assign(fileku,nama);
reset(fileku);
while not EOF(fileku) do begin
readln(fileku,s);
writeln(s);
end;
close(fileku);
readln
end.
{---------------------------------------------------------------------------------}

{-------------------------------Example 8.2----------------------------------}

Program buatfile;
uses wincrt;

87
var fileku: text;
nama : string;
s : string;
begin
clrscr;
write('Nama File yang akan di buat : ');
readln(nama);
assign(fileku,nama);
rewrite(fileku);
writeln('Mulai Menulis');
writeln('Tekan Enter dan spasi untuk berhenti');
while s<>' 'do begin
readln(s);
writeln(fileku,s);
writeln(s);
end;
close(fileku);
readln;
end.
{--------------------------------------------------------------------------------}

D. Exercise
1. Write a variant record declaration for a person that includes the following
information:
a. ID
b. Name
c. Marital Status includes three cases:
 Single
 Married
 Divorced

88
2. Write a variant record declaration for geometric shape that can be used to
calculate the area the Circle: the required information is the radius.
3. Write a variant record declaration for geometric shape that can be used to
calculate the volume of the Cylinder: the required information is the radius and
the height
4. Write a variant record declaration for geometric shape that can be used to
calculate the area and volume of the Sphere: the required information is the
radius.
5. Write a variant record declaration for geometric shape that can be used to
calculate the area and volume of the Cube: the required information is the side.

89
References

Aboulrus, Sam. A. 2000. Learn Pascal. USA: Wordware Publishing, Inc.


Nakamura, S. 1991. Applied Numerical Methods With Software. USA :
Prentice-Hall Inc.
Raharjo, B. 2005. Tekhnik Pemrograman Pascal. Bandung:Informatika.
http//www.htid3ustj.files.wordpress.com/2011/11/pascal.pdf
http//www.achsan.staff.gunadarma.ac.id/Downloads/files/.../Modul+Pascal.pdf
http//www.bayoe.staff.uns.ac.id/files/2009/03/modulstrukturdatapascal1.pdf
http//www.cerdaskreatif.com/.../modul-ti/172-modul-pemrograman-pascal

90
Contents
Chapter 1 ................................................................................................................................... 1
Introduction ................................................................................................................................ 1
A. Basic Concepts Program, Programming and Programming Languages ......................... 1
B. History of Pascal ............................................................................................................. 5
C. Installing Turbo Pascal 7.0 ............................................................................................. 6
D. Exercise .......................................................................................................................... 8
Chapter 2 .................................................................................................................................... 9
Editor Pascal ............................................................................................................................... 9
A. Running Turbo Pascal Editor 7.0..................................................................................... 9
B. Know Your Environment Editor Turbo Pascal 7.0 ...................................................... 11
C. Know the Standards Unit Turbo Pascal 7.0 .................................................................. 14
D. Creating First Program .................................................................................................. 16
E. Exercise ........................................................................................................................ 24
Chapter 3 .................................................................................................................................. 25
Basic Pascal Programming ........................................................................................................ 25
A. Pascal Program Structure ............................................................................................. 25
B. HotKey .......................................................................................................................... 30
C. Pascal Programming Rules............................................................................................ 30
D. Basic Component Pascal Program ................................................................................ 31
E. Pascal Programming Basic Commands ......................................................................... 33
F. Comment ...................................................................................................................... 40
G. Exercises ....................................................................................................................... 41
Chapter 4 .................................................................................................................................. 42

91
Data & Type Operator .............................................................................................................. 42
A. Type of data provided by the PASCAL........................................................................ 42
B. Operator ........................................................................................................................ 45
C. Exercise ......................................................................................................................... 48
Chapter 5 .................................................................................................................................. 50
Selection And Iteration Statements ......................................................................................... 50
A. Selection Statements ....................................................................................................... 50
B. Iteration Statements..................................................................................................... 57
C. Exercises ....................................................................................................................... 63
Chapter 6 .................................................................................................................................. 65
Procedures And Function ......................................................................................................... 65
A. Procedure ..................................................................................................................... 65
B. Function ........................................................................................................................ 68
C. Recursive Function and Procedure ............................................................................... 69
D. Exercise ......................................................................................................................... 70
Chapter 7 .................................................................................................................................. 71
Arrays and Records ................................................................................................................... 71
A. Arrays ............................................................................................................................ 72
B. Records ......................................................................................................................... 79
C. Exercise ......................................................................................................................... 83
Chapter 8 .................................................................................................................................. 84
Data Files .................................................................................................................................. 84
A. The File Type ................................................................................................................. 84
B. Text Files ....................................................................................................................... 85
C. Displaying Text Files...................................................................................................... 87
D. Exercise ......................................................................................................................... 88
References ................................................................................................................................ 90

92

Vous aimerez peut-être aussi