Professional Documents
Culture Documents
Listing Program File
Listing Program File
uses crt ;
type Produk = Record
Kode : String[3] ;
Nama : String[30] ;
Harga : Longint ;
End;
Var
fPro : File of Produk ;
ftemp: File of Produk ;
rPro : Produk ;
lg : Char ;
i : byte ;
xkode: string[8] ;
ketemu: boolean ;
pil : byte ;
procedure openproduk ;
begin
Assign(fpro, 'c:\produk.dat') ;
{$I-} Reset(fpro) ;
{$I+}if IOResult<>0 then Rewrite(fpro) ;
end;
procedure inputproduk ;
begin
OpenProduk ;
Repeat
GotoXY(40,5) ; Write('Input Data Produk') ;
GotoXY(40,6) ; Write('-----------------------------') ;
GotoXY(40,7) ; Write('Kode : ') ; Readln(rpro.Kode) ;
xkode :=rpro.Kode;
i := 1;
seek(fpro,0) ; ketemu := false ;
while not eof(fpro) do
begin
seek(fpro,i-1); read (fpro, rpro) ;
if rpro.kode = xkode then
begin
ketemu := true ;
GotoXY(40,8) ; Write('Nama : ',rpro.Nama) ;
GotoXY(40,9) ; Write('Harga : ',rpro.Harga);
GotoXY(40,10); Write('-----------------------------') ;
GotoXY(40,11); Write('Data Sudah Ada') ;
end;
inc(i);
end;
Rewrite(ftemp) ;
Repeat
GotoXY(40,5) ; Write('Input Data Produk yang dihapus');
GotoXY(40,6) ; Write('-----------------------------') ;
GotoXY(40,7) ; Write('Kode : ') ; Readln(rpro.Kode) ;
xkode :=rpro.Kode;
i := 1;
seek(fpro,0) ; ketemu := false ;
while not eof(fpro) do
begin
seek(fpro,i-1); read (fpro, rpro) ;
if rpro.kode = xkode then
begin
ketemu := true ;
end
else
begin
seek(ftemp,filesize(ftemp));
write(ftemp,rpro) ;
end;
inc(i);
end;
i := 1;
rewrite(fpro) ;
seek(ftemp,0) ;
while not eof(ftemp) do
begin
seek(ftemp,i-1); read (ftemp, rpro) ;
seek(fpro,filesize(fpro));
write(fpro,rpro) ;
inc(i);
end;
procedure menu ;
begin
clrscr ;
Gotoxy(2, 3) ; Write('------------------------') ;
Gotoxy(2, 4) ; Write(' Menu Utama') ;
Gotoxy(2, 5) ; Write('------------------------') ;
Gotoxy(2, 6) ; Write(' 1. Input Produk') ;
Gotoxy(2, 7) ; Write(' 2. Hapus Produk') ;
Gotoxy(2, 8) ; Write(' 3. Informasi Produk') ;
Gotoxy(2, 9) ; Write(' 4. Keluar') ;
Gotoxy(2,10) ; Write('------------------------') ;
Gotoxy(2,11) ; Write(' Pilihan : ') ; readln(pil);
end;
begin
pil := 0 ;
while pil<>4 do
begin
menu ;
case pil of
1 : inputproduk ;
2 : hapusproduk ;
3 : outputproduk ;
end;
end;
end.