Pencarian data didasarkan pada Nomor_induk pegwai
program searching;
uses crt;
label h, z, g, f;
const max=100;
type pegawai=record
nomor : integer;
nama : string[30];
bagian :string[20];
gaji :integer;
end;
tabel=array[1..max] of pegawai;
tabel_1=array[1..max] of integer;
var
a:tabel;
b:tabel_1;
n:integer;
ni:integer;
i, j, temp:integer;
p:char;
pilih:integer;
procedure cari(a:tabel; n:integer; x:integer; var isearch:integer);
var
i:integer;
begin
if(n=0) then isearch:=0 else
begin
i:=1;
while ((a[i].nomor<x) and (i<n)) do
i:=i+1;
if (a[i].nomor=x) then
begin
writeln('Data yang dicari : ');
writeln('Nomor pegawai : ', a[i].nomor);
writeln('Nama pegawai : ', a[i].nama);
writeln('Bagian : ', a[i].bagian);
writeln('Gaji : ', a[i].gaji);
end
else
writeln('Data tidak ditemukan');
end;
end;
procedure biner(a:tabel; n:integer; x:integer; var isearch:integer);
var
bawah, atas:integer;
tengah:integer;
found:boolean;
begin
if (n=0) then isearch:=0 else
begin
bawah:=1;
atas:=n;
found:=false;
while ((not found) and (atas>=bawah)) do
begin
tengah:=(bawah+atas) div 2;
if (a[tengah].nomor=x) then
found:=true
else
if (a[tengah].nomor>x) then
atas:=tengah-1
else
bawah:=tengah+1;
end;
if found then
begin
isearch:=tengah;
writeln('Data yang dicari : ');
writeln('Nomor pegawai : ',a[i].nomor);
writeln('Nama pegawai : ',a[i].nama);
writeln('Bagian : ',a[i].bagian);
writeln('Gaji : ',a[i].gaji);
end;
end;
end;
begin
h:clrscr;
writeln;
writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
writeln('------ SEARCHING DATA ------');
writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
writeln;
writeln;
write('Banyaknya data pegawai : ');readln(n);
writeln;
for i:=1 to n do
begin
write('Nomor pegawai ke-',i,' : '); readln(a[i].nomor);
write('Nama pegawai ke-',i,' : '); readln(a[i].nama);
write('Bagian ke-',i,' : '); readln(a[i].bagian);
write('Gaji ke-',i,' : '); readln(a[i].gaji);
writeln;
end;
z:
writeln;
writeln('*****************************');
writeln('------- MENU SEARCHING ------');
writeln('*****************************');
writeln;
writeln('1. Pencarian Sekuensial');
writeln('2. Pencarian Biner ');
writeln('3. Exit');
write('Pilihan : '); readln(pilih);
writeln;
case pilih of
1:begin
clrscr;
g:
writeln;
writeln('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
writeln('****** PENCARIAN SEKUENSIAL ******');
writeln('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
writeln;
for i:=1 to n-1 do
begin
for i:=1 to n-i do
begin
if (a[j].nomor) > (a[j+i].nomor) then
begin
temp:=a[j].nomor;
a[j].nomor:=a[j+1].nomor;
a[j+1].nomor:=temp;
end;
end;
end;
writeln('Masukkan nomor pegawai yang ingin disearching : '); readln(ni);
writeln;
cari(a,n,ni,i);
writeln;
write('Ingin cari lagi ? (Y/T) : '); readln(p);
if (p='Y') or (p='y') then goto g;
goto z;
writeln;
end;
2:begin
clrscr;
f:
writeln;
writeln('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
writeln('****** PENCARIAN BINER ******');
writeln('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
writeln;
for i:=1 to n-1 do
begin
for j:=1 to n-1 do
begin
if (a[j].nomor) > (a[j+1].nomor) then
begin
temp:=a[j].nomor;
a[j].nomor:=a[j+1].nomor;
a[j+1].nomor:=temp;
end;
end;
end;
writeln;
writeln('Masukkan nomor pegawai yang ingin disearching : '); readln (ni);
writeln;
biner(a,n,ni,i);
writeln;
write('Ingin cari lagi ? (Y/T) : '); readln(p);
if (p='Y') or (p='y') then goto f;
goto z;
writeln;
end;
3:begin
writeln('Program diakhiri');
writeln;
end
else
writeln('Pilihan Salah');
for i:=1 to n do
begin
delay(5000);
end;
goto h;
end;
readkey;
end.
No comments:
Post a Comment