# Algoritma Dan Pemrograman Record

(1)

## Record

(2)

Let’s Start

(3)

(4)

(5)

(6)

Field

Nama Record

(7)

Field

Nama Record

(8)

### Pengaplikasian Record

Definition and Structures of Record

(9)

(10)

(11)

(12)

(13)

(14)

(15)

(16)

(17)

(18)

(19)

(20)
(21)

### Contoh Record (Algorithm)

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

Algoritma RecordDosen

{I.S.: Dideklarasikan dua buah record dosen}

{F.S.: Menampilkan isi record}

Kamus:

type

RecordDosen = record

< NIP : integer, Nama : string, Gaji : real >

endrecord

Dosen1,Dosen2 : RecordDosen

(22)

### Contoh Record(Algorithm)

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

Algoritma:

{input record}

input(Dosen1.NIP) input(Dosen1.Nama) input(Dosen1.Gaji)

input(Dosen2.NIP) input(Dosen2.Nama) input(Dosen2.Gaji)

{Operasi field record}

Dosen1.Gaji  Dosen1.Gaji + 1000000 {Tambah THR}

Dosen2.Gaji  Dosen2.Gaji – 100000 (Karena telat}

(23)

### Contoh Record(Algorithm)

28 29 30 31 32 33 34 35

{Output record}

output(Dosen1.NIP) output(Dosen1.Nama) output(Dosen1.Gaji)

output(Dosen2.NIP) output(Dosen2.Nama) output(Dosen2.Gaji)

(24)

### Contoh Record(Pascal)

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

program RecordDosenIF;

uses crt;

type

RecordDosen=record NIP:longint;

Nama:string;

Gaji:double;

end;

var

Dosen1,Dosen2:RecordDosen;

(25)

### Contoh Record(Pascal)

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

{input record}

write('Masukkan NIP dosen pertama : ');

write('Masukkan Nama dosen pertama : ');

write('Masukkan Gaji dosen pertama : ');

writeln();

write('Masukkan NIP dosen kedua : ');

write('Masukkan Nama dosen kedua : ');

write('Masukkan Gaji dosen kedua : ');

(26)

### Contoh Record(Pascal)

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

Dosen1.Gaji:=Dosen1.Gaji+1000000; {karena THR}

Dosen2.Gaji:=Dosen2.Gaji-100000; {karena telat}

{output record}

writeln();

writeln('NIP dosen pertama = ',Dosen1.NIP);

writeln('Nama dosen pertama = ',Dosen1.Nama);

writeln('Gaji dosen pertama = ',Dosen1.Gaji:0:2);

(27)

### Contoh Record(Pascal)

41 42 43 44 45 46 47 48 49

writeln();

writeln('NIP dosen kedua = ',Dosen2.NIP);

writeln('Nama dosen kedua = ',Dosen2.Nama);

writeln('Gaji dosen kedua = ',Dosen2.Gaji:0:2);

writeln();

end.

(28)

(29)

(30)

(31)

(32)

(33)

(34)

(35)

(36)

(37)

(38)

(39)

(40)

(41)
(42)

### Contoh Array Record (Algorithm)

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

Algoritma ArrayRecordMakananMinuman

{I.S : didefinisikan dua array of record food and drink}

{F.S : menampilkan array of record beserta operasinya}

const

maks=3;

type

RecordMakanan = record

< KodeMakanan:integer, NamaMakanan:string, HargaMakanan:real, DiskonMakanan:real >

endrecord

(43)

### Contoh Array Record(Algorithm)

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

RecordMinuman = record

< KodeMinuman:integer, NamaMinuman:string, HargaMinuman:real, DiskonMinuman:real >

endrecord

{array of record}

ArrayMakanan = array [1..maks] of RecordMakanan;

ArrayMinuman = array [1..maks] of RecordMinuman;

Makanan:ArrayMakanan;

Minuman:ArrayMinuman;

TotalHarga:real;

i:integer;

(44)

### Contoh Array Record(Algorithm)

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

Algoritma:

{input record}

for i  1 to maks do

input(Makanan[i].KodeMakanan) input(Makanan[i].NamaMakanan);

input(Makanan[i].HargaMakanan) input(Makanan[i].DiskonMakanan) endfor

for i  1 to maks do

input(Minuman[i].KodeMinuman) input(Minuman[i].NamaMinuman) input(Minuman[i].HargaMinuman) input(Minuman[i].DiskonMinuman) endfor

(45)

### Contoh Array Record(Algorithm)

43 44 45

46 47 48 49 50 51 52 53

{perhitungan total harga}

TotalHarga  0

for i  1 to maks do

TotalHarga  TotalHarga+(Makanan[i].HargaMakanan

(Makanan[i].HargaMakanan*Makanan[i].DiskonMakanan)) +(Minuman[i].HargaMinuman-

(Minuman[i].HargaMinuman*Minuman[i].DiskonMinuman)) endfor

{output record}

for i  1 to maks do

output(Makanan[i].KodeMakanan) output(Makanan[i].NamaMakanan) output(Makanan[i].HargaMakanan) output(Makanan[i].DiskonMakanan) endfor

(46)

### Contoh Array Record(Algorithm)

54 55 56 57 58 59 60 61

for i  1 to maks do

output(Minuman[i].KodeMinuman) output(Minuman[i].NamaMinuman) output(Minuman[i].HargaMinuman) output(Minuman[i].DiskonMinuman) endfor

output(TotalHarga);

(47)

### Contoh Array Record(Pascal)

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

uses crt;

const

maks=3;

type

RecordMakanan = record KodeMakanan:integer;

NamaMakanan:string;

HargaMakanan:real;

DiskonMakanan:real;

end;

(48)

### Contoh Array Record(Pascal)

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

RecordMinuman = record KodeMinuman:integer;

NamaMinuman:string;

HargaMinuman:real;

DiskonMinuman:real;

end;

{array of record}

ArrayMakanan=array [1..maks] of RecordMakanan;

ArrayMinuman=array [1..maks] of RecordMinuman;

var

Makanan:ArrayMakanan;

Minuman:ArrayMinuman;

TotalHarga:real;

i:integer;

(49)

### Contoh Array Record(Pascal)

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

begin

{input record}

for i:=1 to maks do begin

write('Masukkan kode makanan ',i,' : ');

write('Masukkan nama makanan ',i,' : ');

write('Masukkan harga makanan ',i,' : ');

write('Masukkan diskon makanan ',i,' : ');

end;

(50)

### Contoh Array Record(Pascal)

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

writeln();

for i:=1 to maks do begin

write('Masukkan kode Minuman ',i,' : ');

write('Masukkan nama Minuman ',i,' : ');

write('Masukkan harga Minuman ',i,' : ');

write('Masukkan diskon Minuman ',i,' : ');

end;

(51)

### Contoh Array Record(Pascal)

55 56 57

58 59 60 61 62 63

{perhitungan total harga}

TotalHarga:=0;

for i:=1 to maks do

TotalHarga:=TotalHarga+(Makanan[i].HargaMakanan

(Makanan[i].HargaMakanan*Makanan[i].DiskonMakanan)) +(Minuman[i].HargaMinuman-

(Minuman[i].HargaMinuman*Minuman[i].DiskonMinuman));

{output record}

clrscr();

for i:=1 to maks do begin

(52)

### Contoh Array Record(Pascal)

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

end;

writeln();

for i:=1 to maks do begin

end;

writeln();

writeln('Total harga yang harus dibayar adalah : Rp. ',TotalHarga:0:2);

writeln();