program
data_pegawai;
uses crt;
type
dat = record
nama : string[30];
nidn : string[10];
alamat :
string[25];
pegawai : word;
end;
var
filedat : file of
dat;
data : dat;
pil,Ul : char;
i,x,y : integer;
procedure Menu;
begin
clrscr;
textcolor(white);
writeln('------------------------------------------------------------------');
textcolor(white);
writeln(' Data
Pegawai Perpustakaan Universitas Cokroaminoto Palopo ');
textcolor(white);
writeln('------------------------------------------------------------------');
textcolor(white);
x:=10; y:=8;
gotoxy(x,y+1);
write('1. Tambah Data Pegawai ');
gotoxy(x,y+3);
write('2. Tampilkan Data Pegawai ');
gotoxy(x,y+5);
write('3. Hapus Data Pegawai ');
gotoxy(x,y+7);
write('4. Edit Data Pegawai ');
gotoxy(x,y+9);
write('5. Keluar ');
gotoxy(10,y+12);
write('Pilih Nomor 1 Sampai 5: '); pil:=readkey
end;
procedure
bukafile;
begin
assign
(filedat,'dat.txt');
{$i-};
reset (filedat);
{si+};
end;
procedure Tambah;
var
lagi : char;
ada : boolean;
i : integer;
NOCR : word;
begin
Ul := 'Y';
lagi :='Y';
clrscr;
bukafile;
if
IOResult<>0 then
rewrite
(filedat);
repeat
clrscr;
textcolor(white);
ada:=false;
i:=0;
x:=10; y:=5;
gotoxy(x,y-1);
write('----------------------- ');
gotoxy(x,y);
write (' Tambah Data Pegawai ');
gotoxy(x,y+1);
write('----------------------- ');
gotoxy(x,y+2);
write('Kode : ');readln (NOCR);
while (ada=false)
and (i<>filesize(filedat)) do
begin
seek(filedat,i);
read(filedat,data);
if
data.pegawai=NOCR then
ada:=true
else
inc(i);
end;
if (ada=true)
then
begin
gotoxy(x,y+7);write('Kode
',NOCR,' sudah ada !');
end
else
begin
seek(filedat,filesize(filedat));
data.pegawai:=nocr;
gotoxy(x,y+4);write('Nama :');readln(data.nama);
gotoxy(x,y+5);write('NIDN : ');readln(data.nidn);
gotoxy(x,y+6);write('Alamat : ');readln(data.alamat);
write
(filedat,data);
end;
textcolor(white);
gotoxy(x,y+10);write('Tambah
Data Lagi ? Y/T : ');lagi:=upcase(readkey);
until
lagi<>'Y';
close(filedat);
end;
procedure output;
var
lagi : char;
ada : boolean;
i : integer;
nocr : word;
begin
ul :='Y';
lagi:='Y';
clrscr;
textcolor(white);
bukafile;
if
IOresult<>0 then
write ('Data
Masih Kosong ')
else
begin
repeat
clrscr;
textcolor(white);
ada:=false;
i:=0;
x:=10; y:=2;
gotoxy (x,y+1);
write ('------------------------------------');
gotoxy (x,y+2);
write (' Lihat Data Pegawai ');
gotoxy (x,y+3);
write ('------------------------------------');
gotoxy (x,y+4);
write('Kode : ');readln(nocr);
while (ada=false)
and (i<>filesize (filedat)) do
begin
seek (filedat,i);
read
(filedat,data);
if
data.pegawai=nocr then
begin
textcolor(white);
ada:=true;
x:=10; y:=15;
gotoxy (x,y+1);
write('---------------------------------------------------------------------');
gotoxy (x+0,y+2);
write('Lihat Data Pegawai ');
gotoxy (x+0,y+3);
write('---------------------------------------------------------------------');
gotoxy (x,y+4);
write('Nama : '); writeln
(data.nama);
gotoxy (x,y+5);
write('NIDN : ');writeln
(data.nidn);
gotoxy (x,y+6); write('Alamat : ');writeln (data.alamat);
end
end;
gotoxy(10,13);write('Lihat
Data Lagi? Y/T : ');lagi:=upcase(readkey);
until
lagi<>'Y';
end;
close(filedat);
end;
procedure Edit;
var
lagi : char;
ada : boolean;
i : integer;
nocr : word;
begin
ul :='Y';
lagi:='Y';
clrscr;
textcolor(white);
bukafile;
if
IOresult<>0 then
write ('Data
Masih Kosong ')
else
begin
repeat
clrscr;
textcolor(white);
ada:=false;
i:=0;
x:=10; y:=2;
gotoxy (x,y+1);
write ('------------------------------------');
gotoxy (x,y+2);
write (' Edit Data Pegawai ');
gotoxy (x,y+3);
write ('------------------------------------');
gotoxy (x,y+4);
write('Kode : ');readln(nocr);
while (ada=false)
and (i<>filesize (filedat)) do
begin
seek (filedat,i);
read
(filedat,data);
if
data.pegawai=nocr then
begin
textcolor(white);
ada:=true;
x:=10; y:=15;
gotoxy (x,y+1);
write('---------------------------------------------------------------------------------');
gotoxy (x+0,y+2);
write(' Data Awal | Data Setelah Edit ');
gotoxy (x+0,y+3);
write('-------------------------------------------------------------------------------');
gotoxy (x,y+4);
write('Nama : ');writeln (data.nama);
gotoxy (x,y+5);
write('NIDN : ');writeln (data.nidn);
gotoxy (x,y+6);
write('Alamat : ');writeln (data.alamat);
end
else
inc(i);
end;
if (ada=true)
then
begin
textcolor(white);
data.pegawai:=nocr;
x:=47; y:=15;
gotoxy (x,y+4);
write('Nama :
');readln(data.nama);
gotoxy (x,y+5);
write('NIDN : ');readln(data.nidn);
gotoxy (x,y+6);
write('Alamat :
');readln(data.alamat);
seek(filedat,i);
write(filedat,data);
end
else
begin
textcolor(white);
gotoxy(10,11);write('Kode
Mahasiswa ',nocr,' Tidak Ada ');
end;
textcolor(white);
gotoxy(10,13);write('Edit
Lagi? Y/T ');lagi:=upcase(readkey);
until
lagi<>'Y';
end;
close(filedat);
end;
procedure Hapus;
var
filetmp : file of
dat;
hapus: char;
ada : boolean;
i : integer;
nocr : word;
begin
Ul :='Y';
hapus:='Y';
clrscr;
repeat
bukafile;
if
ioresult<>0 then
write('Data Masih
Kosong ')
else
begin
clrscr;
textcolor(white);
assign(filetmp,'dat.tmp');
rewrite(filetmp);
ada:=false;
i:=0;
x:=10; y:=2;
gotoxy (x+2,y);
write('Hapus Data Pegawai ');
gotoxy (x+1,y+1);
write('----------------------');
gotoxy (x,y+2);
write('Kode : ');readln(nocr);
while (ada=false)
and (i<>filesize(filedat)) do
begin
seek(filedat,i);
read(filedat,data);
if
data.pegawai=nocr then
ada:=true
else
inc(i);
end;
if (ada=true)
then
begin
gotoxy (x,y+4);
write('Nama : ');writeln(data.nama);
gotoxy (x,y+5);
write('NIDN :
');writeln(data.nidn);
gotoxy (x,y+6);
write('Alamat :
');writeln(data.alamat);
gotoxy (x,y+10);
write('Hapus Data Ini ? Y/T : ');readln (hapus);
if upcase
(hapus)='Y' then
begin
for i :=1 to
filesize(filedat) do
begin
seek(filedat,i-1);
read(filedat,data);
if
data.pegawai<>nocr then write(filetmp,data);
end;
close(filedat);
assign(filedat,'dat.txt');
erase(filedat);
assign(filetmp,'data.tmp');
rename(filetmp,'dat.txt');
gotoxy(x-8,y+12);write('Kode
',nocr,' Sudah Dihapus ');
end;
end
else
begin
gotoxy(x-4,y+13);write('Kode
ini Sudah Dihapus',nocr,' Sudah Dihapus ');
end;
gotoxy(x-3,y+15);write('Hapus
Data Yang Lain ? Y/T : ');hapus :=upcase(readkey);
end;
until
hapus<>'Y';
end;
begin
clrscr;
textcolor(white);
writeln('------------------------------------------------------------------');
textcolor(white);
writeln(' Data
Pegawai Perpustakaan Universitas Cokroaminoto Palopo ');
textcolor(white);
writeln('------------------------------------------------------------------');
textcolor(white);
x:=10; y:=8;
gotoxy(x,y+1);
write('1. Tambah Data Pegawai ');
gotoxy(x,y+3);
write('2. Tampilkan Data Pegawai ');
gotoxy(x,y+5);
write('3. Hapus Data Pegawai ');
gotoxy(x,y+7);
write('4. Edit Data Pegawai ');
gotoxy(x,y+9);
write('5. Keluar ');
begin
gotoxy(10,y+12);
write('Pilih Nomor 1 Sampai 5: '); pil:=readkey;
end;
begin
repeat
menu;
case pil of
'1' : Tambah;
'2' : output;
'3' : Hapus;
'4' : Edit;
'5' : Exit;
end;
until(ul<>'Y')or
(pil='5');
end;
end.




