• Tidak ada hasil yang ditemukan

Adam Mukharil Bachtiar English Class Informatics Engineering 2011

N/A
N/A
Protected

Academic year: 2019

Membagikan "Adam Mukharil Bachtiar English Class Informatics Engineering 2011"

Copied!
76
0
0

Teks penuh

(1)

Adam Mukharil Bachtiar

English Class

Informatics Engineering 2011

Algorithms and Programming

(2)

Steps of the Day

Let’s Start

Definition of

Array

One Dimension

Array

Two

Dimensions

Array

(3)

Definition of Array

(4)

Backg

round

of

Arr

a

y

I need a program to process students data but i

want it to

keep all data temporary in memory

(5)

Wha

t

is Ar

ra

y

Data structure that

saves a group of

(6)

Ilus

tr

a

tion

of A

rr

a

y

An Array was named

bil

, has

integer

type,

and consists of

five

elemens.

(7)

T

yp

es of

Arr

a

y

One Dimension Array

Two Dimensions Array

(8)

One Dimension Array

(9)

Wha

t

is O

ne

Dimension

Arr

a

y

(10)

Declar

a

tion

of O

ne

Dimension

Arr

a

y

As variable

As user-defined data type

(11)

Declaration As Variable (Algorithm)

Kamus:

NamaArray : array [1..MaxSize] of TipeData

Contoh:

Kamus:

bil : array [1..5] of integer

NamaDosen : array [1..20] of string

(12)

Declaration As Variable (Pascal)

var

NamaArray : array [1..MaxSize] of TipeData;

Contoh:

var

bil : array [1..5] of integer;

NamaDosen : array [1..20] of string[30];

(13)

Declaration As User-Defined Data Type (Algorithm)

Kamus:

type

NamaArray = array [1..MaxSize] of TipeData

(14)

Declaration As User-Defined Data Type (Algorithm)

Contoh:

Kamus:

type

bil = array [1..5] of integer

bilbulat:bil

(15)

type

NamaArray = array [1..MaxSize] of TipeData;

var

NamaVariabel_1:NamaArray;

NamaVariabel_2:NamaArray;

(16)

Contoh:

type

bil = array [1..5] of integer;

var

bilbulat:bil;

bilpositif:bil;

(17)

Define Size of Array As Constant (Algorithm)

Kamus:

const

MaxSize = VALUE

type

NamaArray = array [1..MaxSize] of TipeData

NamaVariabel_1:NamaArray

(18)

Contoh:

Kamus:

const

maks = 5

type

bil = array [1..maks] of integer

bilbulat:bil

(19)

const

MaxSize = VALUE;

type

NamaArray : array [1..MaxSize] of TipeData;

var

NamaVariabel:NamaArray;

(20)

Contoh:

const

maks = 5;

type

bil = array [1..maks] of integer;

var

bilbulat:bil;

(21)

Ge

t and

se

t

the V

alue

fr

om

Arr

a

y

To fill and access the value in array,

call the name

(22)

Ilus

tr

a

tion

of Se

tting

and

Ge

tting

V

alue

in Arr

a

y

bil[1]=5

it means fill 5 in [1]

(23)

Format of Accessing Array (Algorithm)

namaarray[indeks]

nilai

input(namaarray[indeks])

namaarray[indeks]

namaarray[indeks] + 1

(24)

Format of Accessing Array (Algorithm)

namaarray[indeks] := nilai;

readln(namaarray[indeks]);

namaarray[indeks] := namaarray[indeks] + 1;

(25)

Oper

a

tio

n

in Arr

a

y

Creation

Traversal

Searching

Sorting

(26)

Arr

a

y

Cr

ea

tio

n

Prepare

array to be

accessed/processed

.

Array will be filled with

default value

.

For

numeric array

will be filled with

0

and

for

alphanumeric array

will be filled with

‘ ’

(27)

Procedure create (output NamaVarArray:NamaArray)

{I.S: elemen array diberi harga awal agar siap digunakan} {F.S: menghasilkan array yang siap digunakan}

Kamus:

indeks:integer

Algoritma:

for indeks 1 to maks_array do

nama_var_array[indeks] 0 {sesuaikan dengan tipe array}

endfor

EndProcedure

(28)

procedure create (var NamaVarArray:NamaArray);

var

indeks:integer;

begin

for indeks := 1 to maks do

NamaVarArray[indeks] := 0;

end;

(29)

Arr

a

y

Tr

a

v

er

sal

The process of

visiting all elements

of

array

one by one

, from

the first

(30)

Tr

a

v

er

sal

Pr

oces

ses

Fill elements array with data

Output all elements of array

Adding data to array

Insert data in particular index

Delete data in particular index

Determine maximum and minimum data in

array

(31)

Procedure traversal (I/O NamaVarArray:NamaArray) {I.S: maksimum array sudah terdefinisi}

{F.S: menghasilkan array yang sudah diproses}

Kamus:

Algoritma:

for indeks 1 to maks do {proses traversal}

endfor

Terminasi {sifatnya optional}

EndProcedure

(32)

procedure traversal(var NamaVarArray:NamaArray);

begin

for indeks := 1 to maks do

{proses traversal yang dipilih}

terminasi {sifatnya optional}

end;

(33)

Des

tr

o

y

the Arr

a

y

The process to

return value of array

into

default value

that was given in

(34)
(35)

Example of One Dimension Array (Algorithm)

1 2 3 4 5 6 7 8 9 10 11 12 13 Algoritma ArrayDasar

{I.S.: Dideklarasikan dua buah array satu dimensi} {F.S.: Menampilkan array beserta hasil perhitungan}

Kamus: const

maks=5 type

bil=array[1..maks] of integer

bil1,bil2:bil i:integer

(36)

Example of One Dimension Array (Algorithm)

14 15 16 17 18 19 20 21 22 23 24 25 26 27 Algoritma:

{input elemen array} for i  1 to maks do input(bil1[i])

endfor

for i 1 to maks do input(bil2[i])

endfor

(37)

Example of One Dimension Array (Algorithm)

28 29 30 31 32 33 34 35 37 38 39 40

for i  1 to maks do output(bil2[i]) endfor

{proses perhitungan array} jumlah0;

for i 1 to maks do

jumlahjumlah+bil1[i] endfor

output(jumlah)

(38)

Example of One Dimension Array (Algorithm)

41 42 43 44

for i  1 to maks do

jumlah2jumlah2+bil2[i] endfor

(39)

Example of One Dimension Array (Pascal)

1 2 3 4 5 6 7 8 9 10 11 12 13 program ArrayDasar; uses crt; const maks=5; type

bil=array[1..maks] of integer;

var

bil1,bil2:bil; i:integer;

(40)

Example of One Dimension Array (Pascal)

14 15 16 17 18 19 20 21 22 23 24 25 26 27 begin

{input elemen array} for i:=1 to maks do begin

write('Masukkan nilai ke bil 1 [',i,'] : '); readln(bil1[i]);

end;

writeln();

for i:=1 to maks do begin

write('Masukkan nilai ke bil 2 [',i,'] : '); readln(bil2[i]);

(41)

Example of One Dimension Array (Pascal)

28 29 30 31 32 33 34 35 37 38 39 40

{output elemen array} for i:=1 to maks do begin

writeln('Bil 1[',i,'] = ',bil1[i]); end;

writeln();

for i:=1 to maks do begin

(42)

Example of One Dimension Array (Pascal)

41 42 43 44 45 46 47 48 49 50 51 52 53

{proses perhitungan array} writeln();

jumlah:=0;

for i:=1 to maks do begin

jumlah:=jumlah+bil1[i]; end;

writeln('Jumlah elemen array bil 1 = ',jumlah);

writeln(); jumlah2:=0;

(43)

Example of One Dimension Array (Pascal)

54 55 56 57 58 59 60 61

jumlah2:=jumlah2+bil2[i]; end;

writeln('Jumlah elemen array bil 2 = ',jumlah2);

writeln();

write('Tekan sembarang tombol untuk menutup...'); readkey();

(44)

Two Dimensions Array

(45)

Wha

t

is T

w

o Dimensions

Arr

a

y

Array that has

two subscripts

in its

(46)
(47)

Declaration As Variable (Algorithm)

Kamus:

NamaArray : array [1..MaxBaris,1..MaxKolom] of TipeData

Contoh:

Kamus:

(48)

Declaration As Variable (Pascal)

var

NamaArray : array [1..MaxBaris,1..MaxKolom] of TipeData;

Contoh:

var

matriks: array [1..5,1..5] of integer;

(49)

Declaration As User-Defined Data Type (Algorithm)

Kamus:

type

NamaArray = array [1..MaxBaris,1..MaxKolom] of TipeData

NamaVariabel_1:NamaArray

(50)

Declaration As User-Defined Data Type (Algorithm)

Contoh:

Kamus:

type

matriks = array [1..5,1..5] of integer

(51)

type

NamaArray = array [1..MaxBaris,1..MaxKolom] of TipeData;

var

NamaVariabel_1:NamaArray;

NamaVariabel_2:NamaArray;

(52)

Contoh:

type

matriks = array [1..5,1..5] of integer;

var

matriks1:bil;

matriks2:bil;

(53)

Define Size of Array As Constant (Algorithm)

Kamus:

const

MaxBaris = VALUE1

MaxKolom = VALUE2 type

NamaArray = array [1..MaxBaris,1..MaxKolom] of TipeData

NamaVariabel_1:NamaArray

(54)

Contoh: Kamus: const

MaksBaris = 5 MaksKolom = 5

type

matriks = array [1..MaksBaris,1..MaksKolom] of integer

matriks1,matriks2:bil

(55)

const

MaxBaris = VALUE1; MaxKolom = VALUE2;

type

NamaArray : array [1..MaxBaris,1..MaxKolom] of TipeData;

var

NamaVariabel:NamaArray;

(56)

Contoh: const

MaksBaris = 5; MaksKolom = 5;

type

matriks = array [1..MaksBaris,1..MaksKolom] of integer;

var

bilbulat:bil;

(57)

Oper

a

tio

n

in T

w

o Dimensions

Arr

a

y

(58)

Oper

a

tio

n

in Arr

a

y

Creation

Traversal

Searching

Sorting

(59)

Arr

a

y

Cr

ea

tio

n

Prepare

array to be

accessed/processed

.

Array will be filled with

default value

.

For

numeric array

will be filled with

0

and

for

alphanumeric array

will be filled with

‘ ’

(60)

Procedure create (output NamaVarArray:NamaArray)

{I.S: elemen array diberi harga awal agar siap digunakan} {F.S: menghasilkan array yang siap digunakan}

Kamus:

i,j:integer

Algoritma:

for i 1 to MaksBaris do

for j 1 to MaksKolom do

nama_var_array[i,j] 0 {sesuaikan dengan tipe array}

endfor endfor

EndProcedure

(61)

procedure create (var NamaVarArray:NamaArray);

var

i,j:integer;

begin

for i := 1 to MaksBaris do begin

for j := 1 to MaksKolom do NamaVarArray[i,j] := 0; end;

end;

(62)

Arr

a

y

Tr

a

v

er

sal

The process of

visiting all elements

of

array

one by one

, from

the first

(63)

Tr

a

v

er

sal

Pr

oces

ses

Fill elements array with data

Output all elements of array

Adding data to array

Insert data in particular index

Delete data in particular index

Determine maximum and minimum data in

array

(64)

Procedure traversal (I/O NamaVarArray:NamaArray) {I.S: maksimum array sudah terdefinisi}

{F.S: menghasilkan array yang sudah diproses}

Kamus:

Algoritma:

for i 1 to MaksBaris do for j 1 to MaksKolom do {proses traversal}

endfor endfor

Terminasi {sifatnya optional} EndProcedure

(65)

procedure traversal(var NamaVarArray:NamaArray);

begin

for i := 1 to MaksBaris do

begin

for j := 1 to MaksKolom do

{proses traversal yang dipilih} end;

terminasi {sifatnya optional}

end;

(66)

Des

tr

o

y

the Arr

a

y

The process to

return value of array

into

default value

that was given in

(67)
(68)

Example of Two Dimensions Array (Algorithm)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 Algoritma ArrayDasar

{I.S.: Dideklarasikan dua buah array dua dimensi} {F.S.: Menampilkan isi array}

Kamus: const

MaksBaris=5 MaksKolom=5

type

bil=array[1..MaksBaris,1..MaksKolom] of integer

(69)

Example of Two Dimensions Array (Algorithm)

15 16 17 18 19 20 21 22 23 24 25 26 27 28 Algoritma:

{input elemen array}

for i 1 to MaksBaris do for j 1 to MaksKolom do input(bil1[i,j])

endfor endfor

for i 1 to MaksBaris do for j 1 to MaksKolom do input(bil2[i,j])

(70)

Example of Two Dimensions Array (Algorithm)

29 30 31 32 33 34 35 37 38 39 40 41

{output elemen array}

for i 1 to MaksBaris do for j 1 to MaksKolom do output(bil1[i,j])

endfor endfor

for i 1 to MaksBaris do for j 1 to MaksKolom do output(bil1[i,j])

(71)

Example of Two Dimensions Array (Pascal)

1 2 3 4 5 6 7 8 9 10 11 12 13 program ArrayDuaDimensiDasar; uses crt; const MaksBaris=3; MaksKolom=3; type

matriks = array[1..MaksBaris,1..MaksKolom] of integer;

var

(72)

Example of Two Dimensions Array (Pascal)

14 15 16 17 18 19 20 21 22 23 24 25 26 27 begin {input matriks}

writeln('Input Matriks Pertama'); for baris:=1 to MaksBaris do

begin

for kolom:=1 to MaksKolom do begin gotoxy(kolom*5+1,baris+3); readln(matriks1[baris,kolom]); end; end; writeln();

(73)

Example of Two Dimensions Array (Pascal)

28 29 30 31 32 33 34 35 37 38 39 40

for baris:=1 to MaksBaris do begin

for kolom:=1 to MaksKolom do begin gotoxy(kolom*5+1,baris+9); readln(matriks2[baris,kolom]); end; end; {output matriks} clrscr();

(74)

Example of Two Dimensions Array (Pascal)

41 42 43 44 45 46 47 48 49 50 51 52 53

for baris:=1 to MaksBaris do begin

for kolom:=1 to MaksKolom do begin gotoxy(kolom*5+1,baris+3); write(matriks1[baris,kolom]); end; end; writeln();writeln();

writeln('Output Matriks Kedua'); for baris:=1 to MaksBaris do

(75)

Example of Two Dimensions Array (Pascal)

54 55 56 57 58 59 60 61 62 63 64

for kolom:=1 to MaksKolom do begin gotoxy(kolom*5+1,baris+9); write(matriks2[baris,kolom]); end; end; writeln();

write('Tekan sembarang tombol untuk menutup...'); readkey();

(76)

Contact Person:

Adam Mukharil Bachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: adfbipotter@gmail.com

Blog: http://adfbipotter.wordpress.com

Referensi

Dokumen terkait

Sedangkan untuk variabel rasio gearing , variabel profitabilitas, variabel ukuran perusahaan, variabel struktur kepemilikan pihak luar, dan variabel item-item luar biasa

Untuk mengatasi hambatanyang berasal dari pemilik warnet Polsek Panakkukang akan melakukan penyuluhan agar mereka menyadari dampak negatif dari pornografi

The result of previous research showed that the influence of earnings management to the value of firm, as well as the application of IFRS to the value of firm, but not yet

Tujuan penelitian adalah menganalisis hubungan persepsi visual gambar kesehatan pada kemasan rokok dengan perilaku merokok remaja di SMK Dwija Bhakti 1 Jombang

smart phone pertama yang berbasis android platform dan pada tahun yang sama. Google mengumumkan Android SDK RC 1.0 dibawah lisensi open

Zoonosis dapat ditularkan dari hewan ke manusia melalui beberapa cara, yaitu kontak langsung dengan hewan peng- idap zoonosis dan kontak tidak langsung melalui vektor

Faktor-faktor yang mempengaruhi perilaku konsumen untuk pembelian barang dan jasa sangat bermanfaat untuk dipelajari lebih dalam karena dapat membantu pelaku

a) Perubahan terjadi secara sadar. Ini berarti bahwa seseorang yang belajar akan menyadari perubahan itu atau sekurang- kurangnya ia merasakan telah terjadi suatu perubahan pada