Random News

Perkenalan Array Pada Pascal


Array (
larik ) adalah tipe terstruktur yang terdiri dari sejumlah komponen yang
mempuyai tipe sama.


B.U :
Array [ 1 . . 20 ] of tipe_data ; (Dimensi 1)

B.U :
Array [1 . . 3 , 1 . . 2] of tipe_data; (Dimensi 2)


Contoh
Program Array :

Uses crt ;
Var

Nama : array [1..30 ] of string ;

Tugas, uts, uas, absen : array [1..30] of integer ;

Rata : array [1..30] of real ;

x , jd : byte;
BEGIN
CLRSCR ;
Write (
Masukan Jumlah data :

) ; readln ( jd ) ;

For x : = 1 to jd do
begin

Writeln (
*****************************

) ;

Writeln (
PENILAIAN UJIAN MAHASISWA BSI

) ;

Writeln (
*****************************

) ;

Write (
Input Nama :

) ; readln (nama[x] ) ;

Write (
Input Nilai Tugas :

) ; readln (tugas[x] ) ;

Write (
Input Nilai Absen :

) ; readln (absen[x] ) ;

Write (
Input Nilai UTS :

) ; readln (uts[x] ) ;

Write (
Input Nilai UAS :

) ; readln (uas[x]) ;

Rata[x]:=(0.1*tugas[x])+(0.2*absen[x])+(0.3*uts[x])+(0.4*uas[x]);

End ;
CLRSCR ;
For i : = 1 to j do
Begin

Writeln (
*****************************

) ;

Writeln (
PENILAIAN UJIAN MAHASISWA BSI

) ;

Writeln (
*****************************

) ;

Writeln (
Nama :

, nama[i] ) ;

Writeln (
Nilai Tugas :

, tugas[i] ) ;

Writeln (
Nilai Absen :

, absen[i] ) ;

Writeln (
Nilai UTS :

, uts[i] ) ;

Writeln (
Nilai UAS :

, uas[i]) ;

Writeln (
****************************

) ;

Writeln (
Rata-rata :

, rata : 1: 0 ) ;

Readln ;
End;
END.
Contoh dari Program Array
program ayam_goreng;
uses crt;
var
i,b:byte;
jenis,kdjenis:array [1..50]of string;
banyak,jmlharga,harga:array [1..50]of real;
totb,ppn,totjml,total:real;
begin
clrscr;
writeln(‘Ayam Goreng Fried Chicken’);
writeln(‘========================’);
writeln(‘Kode Jenis potong Harga’);
writeln(‘=============================’);
writeln(‘D Dada 3000 ‘);
writeln(‘P Paha 2500 ‘);
writeln(‘S Sayap 1500 ‘);
writeln(‘=============================’);
write(‘Masukan Jumlah Jenis : ‘);readln(b);
for i:=1 to b do
begin
writeln;
writeln(‘Jenis Ayam ke- ‘,i);
writeln;
write(‘Jenis Ayam Bagian [D/P/S] : ‘);readln(kdjenis[i]);
write(‘Jumlah Beli / Potong : ‘);readln(banyak[i]);
end;
writeln; clrscr;
writeln(‘ PROGRAM AYAM GORENG FRIED CHICKEN’);
writeln(‘======================================================================’);
writeln(‘NO JENIS POTONG HARGA SATUAN BANYAK BELI
JUMLAH HARGA ‘);

writeln;
totb:=0;
for i:=1 to b do
begin
if kdjenis[i]=’D’ then
begin
jenis[i]:=’Dada’;
harga[i]:=3000;
end
else if kdjenis[i]=’P’ then
begin
jenis[i]:=’Paha’;
harga[i]:=2500;
end
else if kdjenis[i]=’S’ then
begin
jenis[i]:=’Sayap’;
harga[i]:=1500;
end
else
begin
jenis[i]:=’Kepala’;
harga[i]:=1000;
end;

jmlharga[i]:=harga[i]*banyak[i];
totb:=totb+jmlharga[i];
ppn:=totb*0.1;
totjml:=totjml+banyak[i];
total:=totb+ppn
end;
for i:=1 to b do
begin

writeln(i:1,jenis[i]:9,harga[i]:14:0,banyak[i]:18:0,jmlharga[i]:19:0);

end;
writeln(‘=================================================================’);
writeln(‘ Jumlah Potong :
‘,totjml:2:0);

writeln(‘ Jumlah bayar :
‘,totb:2:0);

writeln(‘ PPN 10 % :
‘,ppn:2:0);

writeln(‘ Total bayar :
‘,total:2:0);

readln;
end.
Contoh Array Nilai siswa

uses crt;
var Nilai : array[1..50] of real;
jumlah, rata : real;
i,a, JumDat : byte;
nama : string;
begin
clrscr;
{jumlah:=0;}
writeln(‘ Nilai Rata – Rata Praktikum Kelas
TK2A’);


Writeln(‘—————————————’);

write(‘Nama Mahasiswa =’ );readln(nama);
Write(‘Berapa Jumlah data = ‘);readln(JumDat);

for i := 1 to Jumdat do
begin
Write(‘Nilai Praktiklum ke
‘,i,’=’);Readln(Nilai[i]);

end;
jumlah:=0;
for i:= 1 to JumDat do
begin
Jumlah := jumlah + Nilai[i];
rata := Jumlah/JumDat;
end;
writeln;
clrscr;
writeln(‘Nama Mahasiswa =’,nama);

for i := 1 to jumdat do
begin
writeln(‘Nilai Praktekm ke-’,i,’
=’,nilai[i]:3:0);

end;
writeln(‘Total Nilai = ‘, jumlah:8:0);
writeln(‘Nilai Rata – rata = ‘, Rata:8:1);
readln;
end.

Contoh Array
uses crt;
var Nilai : array[1..50] of real;
jumlah, rata : real;
i,a, JumDat : byte;
nama : string;
begin
clrscr;
{jumlah:=0;}
writeln(‘ Nilai Rata – Rata Praktikum Kelas
TK2A’);


Writeln(‘—————————————’);

write(‘Nama Mahasiswa =’ );readln(nama);
Write(‘Berapa Jumlah data = ‘);readln(JumDat);

for i := 1 to Jumdat do
begin
Write(‘Nilai Praktiklum ke
‘,i,’=’);Readln(Nilai[i]);

end;
jumlah:=0;
for i:= 1 to JumDat do
begin
Jumlah := jumlah + Nilai[i];
rata := Jumlah/JumDat;
end;
writeln;
clrscr;
writeln(‘ Nilai Rata – Rata Praktikum Kelas
TK2A’);


Writeln(‘—————————————’);

writeln(‘Nama Mahasiswa =’,nama);
writeln(‘ÉÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍ» ‘);
writeln(‘º Praktikum º Nilai º ‘);
writeln(‘ÌÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍ͹ ‘);

for i := 1 to jumdat do
begin
writeln(‘º’,’ ke-’,i,’ º’,
nilai[i]:3:0,’ º’);


end;
writeln(‘ÈÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍͼ’);
writeln(‘Total Nilai = ‘, jumlah:8:0);
writeln(‘Nilai Rata – rata = ‘, Rata:8:1);
readln;
end.


Contoh Array Agen Bus
Program Harga_Tiket;
uses crt;
var np:array[1..50] of string;
jb:array[1..50] of real;
jbyr:array[1..50] of real;
jml,a:byte;
tot:real;
ask:char;
label
baru;
begin
baru:
clrscr;
textcolor(7);
writeln(‘AGEN BUS MALAM “LENGAH TENTREM”‘);
writeln;
write(‘Masukkan Jumlah Penumpang :
‘);readln(jml);

writeln;
for a:=1 to jml do
begin
writeln(‘Data Ke -’,a);
write(‘Nama Penumpang : ‘);readln(np[a]);
write(‘Jumlah Beli : ‘);readln(jb[a]);
end;
clrscr;
writeln(‘DATA PENJUALAN TIKET’);
writeln(‘AGEN BUS MALAM “LENGAH TENTREM”‘);

writeln(‘—————————————————-’);

writeln(‘No. Nama Penumpang Jumlah Beli
Jumlah Pembayaran’);


writeln(‘—————————————————-’);

for a:=1 to jml do
jbyr[a]:=jb[a]*25000;
for a:=1 to jml do

writeln(a:1,np[a]:10,jb[a]:10:0,jbyr[a]:27:3);

begin

writeln(‘—————————————————-’);


tot:=0;
tot:=tot+jbyr[a];
writeln(‘Total
Pembayaran Rp.’,tot:10:3);


writeln(‘—————————————————-’);

writeln;
write(‘Anda Ingin Memasukkan Data
Selanjutnya [Y/T] ? ‘);readln(ask);

if (ask=’Y’)or(ask=’y’) then goto baru;
end;
end.


Contoh Array data karyawan
uses crt;
var
nama:array[1..10]of string[20];
alamat:array[1..20]of string[30] ;
jml_gaji:array[1..20]of real;
i,j:byte;
begin
clrscr;
write(‘masukan jumlah Data :’);readln(j);
for i:=1 to j do
begin
writeln(‘data ke- ‘,i);
write(‘nama Karyawan :’);readln(nama[i]);
write(‘masukan Alamat :’);readln(alamat[i]);
write(‘jumlah Gaji
:’);readln(jml_gaji[i]);

end;
clrscr;
writeln(‘ DATA GAJI KARYAWAN’);

writeln(‘======================================’);

writeln(‘No. Nama Karyawan Total Gaji ‘);

writeln(‘=======================================’);

for i:=1 to j do
begin
writeln(i:1,nama[i]:15,jml_gaji[i]:15:0);
end;

writeln(‘=======================================’);

readln
end.


Contoh Array Penjualan Susu
Uses crt;
Var i,j:integer;
merk:array[1..5] of string[10];
ukuran:array[1..5] of char;
jumbel,harsat:array[1..5] of integer;
harkot,pot,harsih:array[1..5] of real;
Begin
clrscr;
Write(‘Banyaknya Pembelian : ‘);readln(i);
Writeln;
For j:=1 to i do
Begin
Writeln(‘Data Ke-’,j);
Write(‘Merk Susu : ‘);Readln(merk[j]);
Write(‘Ukuran [K/S/B] :
‘);Readln(ukuran[j]);

Write(‘Jumlah Beli :
‘);Readln(jumbel[j]);


If merk[j]=’Dancow’ then
Case ukuran[j] of
‘K’:harsat[j]:=6500;
‘S’:harsat[j]:=9500;
‘B’:harsat[j]:=13500;
End
Else If merk[j]=’Bendera’ then
Case ukuran[j] of
‘K’:harsat[j]:=8500;
‘S’:harsat[j]:=13500;
‘B’:harsat[j]:=18500;
End
Else
Case ukuran[j] of
‘K’:harsat[j]:=9500;
‘S’:harsat[j]:=16500;
‘B’:harsat[j]:=23500;
End;

If jumbel[j]>=15 then
Begin
harkot[j]:=jumbel[j]*harsat[j];
pot[j]:=0.1*harkot[j];

harsih[j]:=jumbel[j]*harsat[j]-pot[j];

End
Else if jumbel[j]>=30 then
Begin
harkot[j]:=jumbel[j]*harsat[j];
pot[j]:=0.2*harkot[j];

harsih[j]:=jumbel[j]*harsat[j]-pot[j];

End
Else
Begin
harkot[j]:=jumbel[j]*harsat[j];
pot[j]:=0*harkot[j];

harsih[j]:=jumbel[j]*harsat[j]-pot[j];

End;
End;
clrscr;

Gotoxy(1,1);Writeln(‘===========================================================================’);

Gotoxy(2,2);Writeln(‘No’);
Gotoxy(7,2);Writeln(‘Merk’);
Gotoxy(16,2);Writeln(‘Ukuran’);
Gotoxy(24,2);Writeln(‘Jumlah’);
Gotoxy(32,2);Writeln(‘Harga’);
Gotoxy(55,2);Writeln(‘Potongan’);
Gotoxy(70,2);Writeln(‘Total’);
Gotoxy(1,3);Writeln(‘Urut’);
Gotoxy(7,3);Writeln(‘Susu’);
Gotoxy(16,3);Writeln(‘Kaleng’);
Gotoxy(25,3);Writeln(‘Beli’);
Gotoxy(32,3);Writeln(‘Satuan’);
Gotoxy(70,3);Writeln(‘Bayar’);

Gotoxy(1,4);Writeln(‘===========================================================================’);

For j:=1 to i do
Begin
Gotoxy(1,j+4);Writeln(j);
Gotoxy(7,j+4);Writeln(merk[j]);
Gotoxy(18,j+4);Writeln(ukuran[j]);
Gotoxy(26,j+4);Writeln(jumbel[j]);
Gotoxy(32,j+4);Writeln(‘Rp’,harsat[j]);
Gotoxy(55,j+4);Writeln(‘Rp ‘,pot[j]:0:2);
Gotoxy(67,j+4);Writeln(‘Rp ‘,harsih[j]:5:2);
End;

Writeln(‘===========================================================================’);

Readln;
End.


Contoh Array Toko serba ada
uses crt;
var
np:string[20];
jd,i:byte;
nb:array[1..50]of string;
jb,ttl,hrg:array[1..50]of real;
tot:real;
lagi:char;
label awal,akhir;
begin
awal:
clrscr;
writeln(‘TOKO “SERBA ADA”‘);
writeln(‘————————-’);
write(‘masukan nama pembeli :’);readln(np);
write(‘masukan jumlah data :’);readln(jd);
for i:=1 to jd do
begin
writeln(‘data ke- ‘,i);
write(‘nama barang :’);readln(nb[i]);
write(‘jumlah beli :’);readln(jb[i]);
write(‘harga :’);readln(hrg[i]);
end;
clrscr;
writeln(‘ TOKO “SERBA
ADA”‘);

writeln(‘ TABEL PENJUALAN
BARANG’);


writeln(‘———————————————————–’);

writeln(‘No. Nama pembeli Nama barang
Jumlah harga total ‘);


writeln(‘———————————————————–’);

tot:=0;
for i:=1 to jd do
begin
ttl[i]:=hrg[i]*jb[i];
tot:=tot+ttl[i];
end;
for i:=1 to jd do
begin

writeln(i:1,np:10,nb[i]:13,jb[i]:12:0,hrg[i]:8:0,ttl[i]:10:0);

end;

writeln(‘————————————————————-’);

writeln(‘total bayar
= ‘,tot:3:0);


writeln(‘————————————————————-’);

write(‘Mau input data
lagi[Y/T]=’);readln(lagi);

if (lagi=’Y’) or (lagi=’y’) then
goto awal
else
goto akhir;
akhir:
readln;
end.


Contoh Array Bengkel
program bengkel;
uses crt;
var
i,b:byte;
nm,nmoli,jnsmbl:array [1..50]of string;
hrg,bonus,hrgsev,hrgoli,tot:array [1..50]of
real;

totb:real;
begin
clrscr;
writeln(‘BENGKEL MAJU MUNDUR’);
writeln(‘========================’);
write(‘Masukan data: ‘);readln(b);
for i:=1 to b do
begin
writeln(‘data ke- ‘,i);
writeln;
write(‘nama pengunjung :’);readln(nm[i]);
write(‘jenis kendaraan [1. mobil| 2.
motor]:’);readln(jnsmbl[i]);

write(‘jenis oli [ 1. castrol| 2. pelumas
pertamina]:’);readln(nmoli[i]);

end;
writeln;
writeln(‘ PROGRAM SERVIC BENGKEL
MAJU MUNDUR’);


writeln(‘======================================================================’);

writeln(‘NO NAMA PENGUNJUNG JENIS
KENDARAAN JENIS OLI TOTAL ‘);

writeln;
totb:=0;
for i:=1 to b do
begin
if jnsmbl[i]=’1′ then
hrgsev[i]:=30000
else
hrgsev[i]:=20000;
if nmoli[i]=’2′ then
hrgoli[i]:= 20000
else
hrgoli[i]:=30000;
tot[i]:=hrgsev[i]+hrgoli[i];
totb:=totb+tot[i];
end;
for i:=1 to b do
begin

writeln(i:1,nm[i]:9,hrgsev[i]:14:0,hrgoli[i]:18:0,tot[i]:19:0);

end;

writeln(‘=================================================================’);

writeln(‘total bayar
:’,totb:2:0);

readln;
end.

Contoh Array Kereta

uses crt;
var
jp,i:byte;
np,nk:array[1..50]of string;
fsl:array[1..50]of char;
jml,hrg,ttl:array[1..50]of real;
tot:real;
lagi:char;
label awal,akhir;
begin
awal:
clrscr;
writeln(‘STASIUN “HARUS BERHENTI” ‘);
writeln(‘================================’);
write(‘masukan jumlah pemesan :’);readln(jp);
for i:=1 to jp do
begin
writeln(‘Data ke- ‘,i);
write(‘Nama pemesan :’);readln(np[i]);
write(‘Nama kereta :’);readln(nk[i]);
writeln(‘fasilitas [ 1.VVIP 3.BISNIS ');
write(' 2.VIP 4.EKONOMI ]
=’);readln(fsl[i]);

write(‘jumlah pesan :’);readln(jml[i]);
end;
writeln(‘ STASIUN “HARUS
BERHENTI” ‘);

writeln(‘ PROGRAM PENJUALAN TIKET
KERETA API’);


writeln(‘————————————————————————-’);

writeln(‘NO. Nama Pemesan Nama Kereta
Fasilitas Jumlah Pesan harga total’);

tot:=0;
for i:=1 to jp do
begin
if fsl[i]=’1′ then
hrg[i]:=200000
else
if fsl[i]=’2′ then
hrg[i]:=180000
else
if fsl[i]=’3′ then
hrg[i]:=140000
else
hrg[i]:=80000;
ttl[i]:=hrg[i]*jml[i];
tot:=tot+ttl[i];
end;
for i:=1 to jp do
begin

writeln(i:1,np[i]:10,nk[i]:12,fsl[i]:15,jml[i]:14:0,hrg[i]:12:0,ttl[i]:10:0);

end;
writeln(‘————————————————————————–’);
writeln(‘total pembayaran
=’,tot:9:0);

writeln(‘————————————————————————–’);
write(‘Mau input data lagi[Y/T]=’);readln(lagi);
if (lagi=’Y’) or (lagi=’y’) then
goto awal
else
goto akhir;
akhir:
readln;
end.
Share on Google Plus

About Unknown

    Blogger Comment
    Facebook Comment

0 opmerkings: