Silahkan dicopy dan dimodifikasi agar menjadi lebih lengkap dan bisa dijadikan pembelajaran bagi yang lain. Berikut ini adalah contoh program pascal untuk menghitung gaji karyawan.
program record_desember;
uses wincrt;
type karyawan=record
nik,nama:string;
gol:1..3;
status:1..2;
gaji:real;
end;
larik_kar=array[1..20] of karyawan;
var kar,bayangan:larik_kar;
i,j,n:byte; lagi:string;
pil:1..8;
function hitung_gaji(a:byte;b:byte):real;
var pokok:longint;
begin
pokok:=500000;
if (b=0) and (a=1) then hitung_gaji:=pokok+(0.1*pokok) else
if (b=1) and (a=1) then hitung_gaji:=pokok+(0.25*pokok) else
if (b=0) and (a=2) then hitung_gaji:=(pokok*1.5)+(0.1*pokok) else
if (b=1) and (a=2) then hitung_gaji:=(pokok*1.5)+(0.25*pokok) else
if (b=0) and (a=3) then hitung_gaji:=(pokok*2.5)+(0.1*pokok) else
hitung_gaji:= (pokok*2.5)+(pokok*0.25);
end;
procedure isi(var x:larik_kar);
var lagi:char;
begin
repeat
begin
inc(n);
writeln('mengisi data ke',n);
write('nik : ');readln(x[n].nik);
write('nama : ');readln(x[n].nama);
write('gol : ');readln(x[n].gol);
write('1 menikah,0belum : ');readln(x[n].status);
x[n].gaji:=hitung_gaji(x[n].gol,x[n].status);
writeln;
write('mau lagi? (y/t) ');readln(lagi);
end
until (lagi<>'y');
end;
procedure cetak(var x:larik_kar);
var bantu1,bantu2:string;
begin
writeln(' DATA KARYAWAN');
writeln('-------------------------------------------------------------------------');
writeln('NO NIK NAMA GOL STATUS GAJI ');
writeln('==========================================================================');
for i:=1 to n do
begin
with x[i] do
begin
if (x[i].gol=1) then bantu1:='OB' else if (x[i].gol=2) then
bantu1:='supervisor' else bantu1:='manager';
if (x[i].status=0) then bantu2:='TM' else bantu2:='M';
writeln(i:2,' ',nik:4,' ',nama:15,' ',bantu1:12,' ',bantu2:15,' ','Rp',gaji:10:2);
end;
end;
writeln('==========================================================================');
end;
procedure filtergol(var x:larik_kar);
var pil_gol:1..3;
begin
writeln;
writeln('pilih golongan yang difilter');
writeln('1. gol3 manager');
writeln('2. gol2 super');
writeln('3. gol1 ob');
write('pilih ==> ');readln(pil_gol);
if (pil_gol=1) then
begin
writeln('gol manager');
for i:=1 to n do
if (x[i].gol=3) then writeln(i:2,' ',x[i].nik:6,' ',x[i].nama:15);
end
else
if (pil_gol=2) then
begin
writeln('gol super');
for i:=1 to n do
if (x[i].gol=2) then writeln(i:2,' ',x[i].nik:6,' ',x[i].nama:15);
end
else
begin
writeln('gol manager');
for i:=1 to n do
if (x[i].gol=1) then writeln(i:2,' ',x[i].nik:6,' ',x[i].nama:15);
end;
end;
procedure hapus(var x:larik_kar);
var rec_hapus:byte;
begin
write('hapus yang mana? ');readln(rec_hapus);
for i:=rec_hapus to (n-1) do x[i]:=x[i+1];
dec(n);
writeln('no record',rec_hapus,' sudah dihapus');
end;
procedure editt(var x:larik_kar);
var rec_edit:byte;
begin
write('edit yang mana? ');readln(rec_edit);
writeln('edit data ke',rec_edit);
write('nik : ');readln(x[rec_edit].nik);
write('nama : ');readln(x[rec_edit].nama);
write('gol : ');readln(x[rec_edit].gol);
write('1 menikah,0belum : ');readln(x[rec_edit].status);
x[rec_edit].gaji:=hitung_gaji(x[rec_edit].gol,x[rec_edit].status);
writeln;
writeln('no record',rec_edit,' sudah diedit');
end;
procedure cari_nama(var x:larik_kar);
var cari:string;
cacah:byte;
begin
repeat
begin
clrscr;
cacah:=0;
writeln(' cetak data pegawai ');
writeln;
write('masukkan nama = ');readln(cari);
writeln;
for i:=1 to n do
begin
if x[i].nama=cari then
begin
inc(cacah);
writeln('======================================================');
end;
end;
if cacah=0 then writeln('maaf, nama yang anda cari tidak ada',cari,'tidak terdaftar')
else
writeln;
write('mau mencari lagi<y/t> =');readln(lagi);
end;
until(lagi<>'y');
end;
procedure sorting_gaji(var x:larik_kar);
var sementara:karyawan;
begin
{memindahkan data asli ke laik bayangan}
for i:=1 to n do bayangan[i]:=x[i];
{proses sorting}
for i:=1 to n-1 do
begin
for j:=i+1 to n do
begin
if (bayangan[i].gaji<bayangan[j].gaji) then
begin
sementara:=bayangan[i];
bayangan[i]:=bayangan[j];
bayangan[j]:=sementara;
end;
end;
end;
writeln('data karyawan sesuai gaji');
writeln; cetak(bayangan);
end;
procedure filtergaji(var x:larik_kar);
var pil:1..6;
cacah:byte;
begin
repeat
begin
clrscr;
writeln('daftar gaji pegawai');
cacah:=0;
writeln('1. Rp.1,500,000');
writeln('2. Rp.2,000,000');
writeln('3. Rp.2,500,000');
writeln('4. Rp.3,000,000');
writeln('5. Rp.3,000,000');
writeln('6. Rp.4,500,000');
write('pilih 1-6 =>');readln(pil);
if pil= 1 then
begin
writeln('pegawai dengan gaji Rp.1,500,000 : ');
writeln;
for i:=1 to n do
begin
if x[i].gaji=1500000 then
begin
inc(cacah);
write('nik : ');readln(x[n].nik);
write('nama : ');readln(x[n].nama);
write('gol : ');readln(x[n].gol);
writeln('============================');
end;
end;
if cacah=0 then writeln('tidak ada gaji pegawaiyang terdaftar dengan gaji berikut')
else
writeln;
end
else
if pil= 2 then
begin
writeln('pegawai dengan gaji Rp.2,000,000 : ');
writeln;
for i:=1 to n do
begin
if x[i].gaji=2000000 then
begin
inc(cacah);
write('nik : ');readln(x[n].nik);
write('nama : ');readln(x[n].nama);
write('gol : ');readln(x[n].gol);
writeln('============================');
end;
end;
if cacah=0 then writeln('tidak ada gaji pegawaiyang terdaftar dengan gaji berikut')
else
writeln;
end
else
if pil= 3 then
begin
writeln('pegawai dengan gaji Rp.2,500,000 : ');
writeln;
for i:=1 to n do
begin
if x[i].gaji=2500000 then
begin
inc(cacah);
write('nik : ');readln(x[n].nik);
write('nama : ');readln(x[n].nama);
write('gol : ');readln(x[n].gol);
writeln('============================');
end;
end;
if cacah=0 then writeln('tidak ada gaji pegawaiyang terdaftar dengan gaji berikut')
else
writeln;
end
else
if pil= 4 then
begin
writeln('pegawai dengan gaji Rp.3,000,000 : ');
writeln;
for i:=1 to n do
begin
if x[i].gaji=3000000 then
begin
inc(cacah);
write('nik : ');readln(x[n].nik);
write('nama : ');readln(x[n].nama);
write('gol : ');readln(x[n].gol);
writeln('============================');
end;
end;
if cacah=0 then writeln('tidak ada gaji pegawaiyang terdaftar dengan gaji berikut')
else
writeln;
end
else
if pil= 5 then
begin
writeln('pegawai dengan gaji Rp.3,500,000 : ');
writeln;
for i:=1 to n do
begin
if x[i].gaji=3500000 then
begin
inc(cacah);
write('nik : ');readln(x[n].nik);
write('nama : ');readln(x[n].nama);
write('gol : ');readln(x[n].gol);
writeln('============================');
end;
end;
if cacah=0 then writeln('tidak ada gaji pegawaiyang terdaftar dengan gaji berikut')
else
writeln;
end
else
if pil= 6 then
begin
writeln('pegawai dengan gaji Rp.4,000,000 : ');
writeln;
for i:=1 to n do
begin
if x[i].gaji=4000000 then
begin
inc(cacah);
write('nik : ');readln(x[n].nik);
write('nama : ');readln(x[n].nama);
write('gol : ');readln(x[n].gol);
writeln('============================');
end;
end;
if cacah=0 then writeln('tidak ada gaji pegawaiyang terdaftar dengan gaji berikut')
else
writeln;
end
else
write('filter data lagi<y/t> =');readln(lagi);
end;
until (lagi<>'y');
end;
begin
repeat
begin
clrscr;
writeln(' DATA KARYAWAN');
writeln('1. isi');
writeln('2. cetak');
writeln('3. cari dasar gaji');
writeln('4. cari dasar gol');
writeln('5. cari karyawan');
writeln('6. edit data');
writeln('7. hapus dasar no');
writeln('8. sorting gaji');
writeln('9. selesai');
write('pilihan anda? ');readln(pil);
case pil of
1: isi(kar);
2: cetak(kar);
3: filtergaji(kar);
4: filtergol(kar);
5: cari_nama(kar);
6: editt(kar);
7: hapus(kar);
8: sorting_gaji(kar);
9: writeln('makasiiii');
end;
readln;
end;
until (pil=8);
end.
0 komentar:
Posting Komentar