You are on page 1of 42

Physics of FST UIN Jakarta

2018
Turbo Pascal
Programming

To understand what the meaning of programming language let us consider


the following analogy. Suppose you are in a place or village that does not
have the same language as you. What would you do to communicate with
the villagers? Of course there are two ways that can be done are:

A.You are the parents of the villagers


B.You are looking for a citizen who understands your language
But of course the above two ways require
time and persistence. Then the question is,
is there any other way that can be done in
order to communicate more quickly? Of
course there is, that is using the Indonesian
language. Of course on condition that you
and the people you meet both should
understand the Indonesian language.
So in the above example, Indonesian is the
language of communication between two
different people. The same is true in the field
of computing, which communicates with
people and computers. As you understand,
people have their own language and the
computer also has its own language: machine
language. Because the computer is not
possible to learn to learn the language of
people, if you want to communicate with the
computer then people who have to learn
machine language. But machine language is
quite complicated and not everyone wants to
learn it.
It is therefore created that is
easily learned by people and
understood by computers.
This language is called the
Programming Language.
At the moment there are many programming languages ​such
as, BASIC, FORTRAN, C, Pascal, PROLOG, and so forth.
Besides that every language is still consisted of several
versions, for example for BASIC known BASIC microsoft,
Basic Turbo, Quick BASIC and so forth.

Why should there be many programming languages? This


question is almost the same as the question, Why in this
world there are many languages ​(people) ?
The second question can be directly
answered, because in this world there
are so many different nation's customs
and environment. Which language is the
best? The best thing is if we are in Thai
use Thai language, if in Italy use italian
language, when in Uganda use Uganda
language and so on.
So is the case with programming
languages. Created a lot of
programming languages ​because in this
world there are so many problems and
every kind of problem will be solved
efficiently when a particular
programming language is used. Here
will only be discussed Turbo Pascal
programming language, which is one
version of Pascal programming
language created by Borland specifically
for use on micro computers.
Unlike the case with the programming language FORTRAN,
BASIC and PROLOG are all written in uppercase, then
Pascal is only the first letter that is written with a capital letter.
This is because the name of this programming language is
taken from the name of a French scientist Blaise Pascal
(1623 - 1662), while the other is an abbreviation.
Now let's first discuss the reasons why Pascal chose
not others. This selection is based on Pascal's
structured nature that the program consists of small
sections called Blocks, which complete a job
thoroughly making it easy to browse if the program
requires any improvement or adjustment. In addition,
with the existence of this structured pattern is very
easy in assembling a program because we do not
need to think about all the work simultaneously but
can gradually.
So if the work is analogous to the work of making
a house, then after knowing the desired shape of
the house then we can focus attention in making
windows, doors, bathrooms, and so on. After
everything is done then we combine to form a
house.
Secondly, the reason why Turbo
Pascal is chosen is not Pascal like
Pascal MT, the reason is that we
want to focus all the attention on
programming so that everything that
is supporting the nature of the work
should be as simple as possible. At
this time Pascal's only eligible
Pascal
Turbo using an editor is very similar
to WordStar, one of the most
popular word processors. So it is not
wrong to say that in learning Turbo
Pascal we also learn WordStar. So
that completed with Turbo Pascal
you will gain double knowledge of
assembling the program and typing
with the computer.
Parts of Turbo Pascal
Programe
As with the language we know everyday,
programming languages ​also have a grammar
that must be learned first before using the
programming language in question. We start with
the smallest element of a language that is the
letters in the programming language is the
character. Actually this character is not exactly the
same as the letters in everyday language
because the character consists of three groups,
namely letters, numbers and special marks.
In addition the following
In Pascal Turbo the
couples are also included
letters are known are: a
groups of special signs:
through z A up to Z _
<= =>: = .. (* *) (.) Couple
(underline) Numbers
(* is equivalent to
consist of: 0 1 2 3 4 5 6 7
{and *) together with
8 9 Custom signs consist
} (. Together with [ .)
of: + - * / = <> [] {} (). ,; : ^
together with ]
@ $ # space
Next thing to know is how to form
a word that in programming
language called variable name.
For Pascal Turbo version 5.0 a
variable name can consist of an
infinite number of characters, but
only 63 characters will start 64
characters and so will be ignored
by Pascal Turbo.
Additionally the variable name
must be eligible:

• first character must be letter


1

• does not contain any special


2 characters

• not one of those words of


3 savings.
The word stash is a variable name that has a certain meaning in the
programming language. For TP version 5.0 the stash words are:
Title Section

Pascal Turbo Declaration


program Section
structure

Body Section
• Consists of the word
Title savings program followed
Section by the name of the
program.

• to declare the variable type


Declaration used in the program
Section

• Is a prosen that contains input,


operational and output
Body Section
Constsants

Function Variable

Declarations
Type

Procedure Type

Label
Constant Declaration

Used if the identifier is a constant beginning


with the word const reserve. This declaration
is used to tell Pascal Turbo that the names
declared here have a fixed value. Which can
be declared here such as the quantities of
physics whose value remains the rate of
light, the charge of an electron, and so forth.
Example
When the program is run, results
will be obtained:

Potongan = 2.0000000000-01
Gaji = 25000
Nama = P.T Lali Jiwo
Variable Declaration

If the identifier is a data that is usually


changed (not constant) then used variable
declaration. Variable declarations are almost
always used in any lengthy program. The Var
reserve word as the variable declaration title is
followed by one or more comma-separated
word identifiers (,), followed by colon (:) and
the type of data and end with a semicolon (;).
Var
Total, Gaji, Tunjangan:real;
Menikah : Boolean;
JumlahAnak : integer; Variable Declaration
Keterangan : String[25];
Begin
Gaji := 50000;
Menikah := true;
JumlahAnak := 3;
Tunjangan := 0.25*Gaji + JumlahAnak * 30000.0;
Total := Gaji + Tunjangan;
Keterangan := ‘Karyawan Teladan’;
Writeln (‘Gaji bulanan : Rp ‘,Gaji);
Writeln (‘Tunjangan : Rp ‘,Tunjangan);
Writeln (‘Total Gaji : Rp ‘,Total);
Writeln (‘Sudah menikah : Rp ‘,Menikah);
Writeln (‘JumlahAnak : Rp ‘,JumlahAnak);
Writeln (‘Keterangan : Rp ‘,Keterangan);
End.
Programe Using Variable Declaration
Bila program ini dijalankan akan dihasilkan:

Gaji bulanan : Rp 5.0000000000E+04


Tunjangan : Rp 1.0250000000E+05
Total Gaji : Rp 1.5250000000E+05
Sudah Menikah : True
Jumlah Anak :3
Keterangan : Karyawan Teladan
This variable declaration section is divided into two groups: Standard variable
Nonstandard variables Included in the standard group of variables are:
integers, real numbers, characters and booleans.

The group of integers consists of 5 sub-groups as


below:

Shortint ( -128 s/d 127; memory 1 byte),


Integer (-32768 s/d 32767; memory 2 byte)
Longint (-2147483648 s/d 2147483647; memory 4
byte)
Byte (0 s/d 255; memori 1 byte)
Word (0 s/d 65535; memori 2 byte)
The group of real numbers is also divided into 5
sub groups as follows:

real (2,9 x 10-39 s/d 1,7 x 10+38; memori 6 byte)


single (1,5 x 10-45 s/d 3,4 x 10+38; memori 6 byte)
double (5,0 x 10-324 s/d 1,7 x 10+4932; memori 8 byte)
extended (3,4 x 10-4932 s/d 1,1 x 10+4932; memori 10 byte)
comp (-2+63 + 1 s/d 2+63- 1; memori 8 byte)
Type Declaration

In pascal there are many types that are provided,


among others:

a. Tipe data sederhana


(simple-type data) b. Tipe data terstruktur
i. Tipe data standar (Structured-type data)
- integer - array
- real - record
- file
- char
- set
- Boolean c. Tipe data penunjuk (pointer-
- String type data) Kata cadangan type
ii Tipe data didefenisikan digunakan sebagai judul
pemakai deklarasi tipe dan diikuti oleh
- enumerated atau scalar type satu atau lebih defenisi tipe
- subrange type yang dipisahkan oleh titik koma.
Example of declaring a simple data type:

Type
Pecahan = real;
Logika = Boolean; bagian defenisi tipe
Bulat = integer;
Huruf = string [25];
Begin
End.

Programe With simple type declaration


From the declaration of the data type, it means
that you do not have to specify the data type is
real, but can use the word fraction. Similarly,
Boolean data types, integers and strings [25], can
be successively replaced by logical, round and
letter words in variable declarations like the
following example:
Type
Pecahan = real;
Logika = Boolean; deklarasi tipe
Bulat = integer;
Huruf = string [25];
Var
Total, Gaji, Tunjangan ::Pecahan;
Menikah : logika;
JumlahAnak : bulat; Deklarasi Variabel
Keterangan : huruf];

BeginT
Gaji := 50000;
Menikah := true;
JumlahAnak := 3;
Tunjangan := 0.25*Gaji + JumlahAnak * 30000.0;
Total := Gaji + Tunjangan;
Keterangan := ‘Karyawan Teladan’;
Writeln (‘Gaji bulanan : Rp ‘,Gaji);
Writeln (‘Tunjangan : Rp ‘,Tunjangan);
Writeln (‘Total Gaji : Rp ‘,Total);
Writeln (‘Sudah menikah : Rp ‘,Menikah);
Writeln (‘JumlahAnak : Rp ‘,JumlahAnak);
Writeln (‘Keterangan : Rp ‘,Keterangan);
End.

Programs with variable declarations using the declared identifier type


Label Declaration

Used if the program uses goto statements to jump


to a particular statement. Declaring it begins with the label
identifiers separated by a semicolon (;)

Procedure Declaration

Is a separate part of the program and can be activated anywhere in the


program. The backup word procedure is used as the title of the procedure
declaration, followed by the identifier which is the name of the procedure
followed by the set of parameters ending in a semicolon.
As:
PROCEDURE Hitung(X,Y:integer);

Keterangan: PROCEDURE (kata cadangan), Hitung (identifier prosedur) dan


X,Y (parameter).
Program Contoh_Prosedur(layer);
prosedur tambah (x,y:integer;Var hasil: integer);
begin bagian deklarasi prosedur

Hasil := x + y ;

End;
{program utama}
Var
Z : integer;
Begin
Tanbah(2,3,z);
Writeln(‘2 +3 =’, Z);
End.

Program using procedure declaration

When the program run results


obtained
2+3=5
. Function Declaration

Almost similar to the procedure, but begins with the word backup
function is followed by function names, parameters and function
types. as:

FUNCTION Pangkat(X,Y : real) : real;

Program Contoh_Fungsi(layer);
Functionr tambah (x,y:integer) : integer;
begin function declaration section

tambah := x + y ;

End;
{program utama}
Begin
Writeln(‘2 +3 =’, Tambah(2,3));
End.

Program with function declaration


When the program is run the results
obtained:
2+3=5
Section of Input and Output

Working with a microcomputer allows us to have a


dialogue with the computer so we know what it should
do. Such programs are called user friendly programs,
and can be created by slipping messages between
commands. Since this dialogue is a very important
complement to the program run on microcomputers
then in this section will be discussed how to make the
dialogue. But beforehand will be reviewed in advance
the properties of the input and output section. For a
while we limit first that the data is read through the
keyboard and written on the screen.
Input Section

There are two commands to read data:


Read, when used then after reading the
cursor data will remain beside the data.
Readln, When used then if reading the
cursor data will move to column 1 of the
next line. Both read and readln have
formatting:

Read [ln] (var[,var1,var2,..])


Output Section
As with the input section, this section also
consists of two kinds, namely: Write, when used then
after writing the cursor data will remain next to the
data. Writeln, when used then after writing the data,
the cursor will move to column 1 of the next line. Both
Write and Writeln have the following formats:

Write [ln] (var[,var1,var2,..])

Based on the above rules we can create a


combination of output with input, where the output is
used to write messages and input is used to read
data. So the user of the program will know what to
do.
THANK YOU
See you next
week

You might also like