Program DataPerpustakaan;
Uses wincrt;
const
garis1 = '---------------------------';
garis2 ='=============================================================';
garsed1= '-----------------------';
garsed2='============================================================';
gar1 = '------------';
gar3 = '==========================';
garspas= '
===========================================================';
teks1 = ' PROGRAM PERPUSTAKAAN';
teks2 = 'UNIVERSITAS SRIWIJAYA';
teks3 = '2011';
Type
perpustakaan = Record
{type utk Buku}
KdBuku : word;
Judul : String[20]; Jenis : string[20];Pengarang :
string[20];Penerbit : string[20];
JBuku:word;
Harga,Telat, Denda : Real;
End;
Var
Fileperpustakaan : File of Perpustakaan;
Data : Perpustakaan;
Pil,Ul : Char;
x,y,i : integer;
Procedure Title;
begin
gotoxy(27,1); writeln(teks1);
gotoxy(28,2); writeln(teks2);
gotoxy(38,3); writeln(teks3);
gotoxy(1,4); writeln(garis2);
end;
Procedure Menu;
Begin
Clrscr;
title;
x:=30; y:=6;
Gotoxy(34,y);Write('MENU UTAMA');
Gotoxy(33,y+1);Write('============');
Gotoxy(x,y+2);Write('1. TAMBAH DATA BUKU');
Gotoxy(x,y+3);Write('2. EDIT DATA BUKU');
Gotoxy(x,y+4);Write('3. HAPUS DATA BUKU');
Gotoxy(x,y+5);Write('4. TAMPILKAN DATA BUKU');
Gotoxy(x,y+6);Write('5. KELUAR PROGRAM');
Gotoxy(31,y+7);Write('Pilihan [1..5]');Pil:=Readkey;
End;
Procedure BukaFile;
Begin
Assign(Fileperpustakaan,'perpustakaan.txt');
{$I-};
Reset(Fileperpustakaan);
{$I+};
End;
Procedure Tambah;
Var
Lagi: Char; Ada : Boolean; i : Integer; NOCR: Word;
JBuku:integer;
Begin
Ul :='Y';
Lagi:='Y';
Clrscr;
BukaFile;
If IOResult<>0 then
Rewrite(Fileperpustakaan);
Repeat
Clrscr;
title;
Ada:=False;
i:=0;
x:=28;y:=5;
Gotoxy(x+4,y);Write('TAMBAH DATA BUKU');
Gotoxy(x+4,y+1);Write('---------------');
Gotoxy(x,y+2);Write('Kode Buku : ');Readln(NOCR);
While (Ada=False) And
(i<>filesize(Fileperpustakaan))Do
Begin
Seek(Fileperpustakaan,i);
Read(Fileperpustakaan,Data);
If Data.KdBuku=NOCR Then
Ada:=True
Else
Inc(i);
End;
If (Ada=True) Then
Begin
Gotoxy(x-5,y+7);Write('Kode Buku "',NOCR,'"Ini
sudah ada!');
End
Else
Begin
Seek(Fileperpustakaan,Filesize(Fileperpustakaan));
Data.KdBuku:=NOCR;
Gotoxy(X,y+3);Write('Judul Buku : ');Readln(Data.judul);
Gotoxy(X,y+4);Write('Jenis Buku : ');Readln(Data.Jenis);
Gotoxy(X,y+5);Write('Pengarang : ');Readln(Data.Pengarang);
Gotoxy(X,y+6);Write('Penerbit : ');Readln(Data.Penerbit);
Gotoxy(X,y+7);Write('Harga Sewa : ');Readln(Data.Harga);
Gotoxy(X,y+8);write('Jumlah Buku: '); Readln(Data.JBuku);
Write(FilePerpustakaan,Data);
End;
Gotoxy(x,y+9);Write('Apakah Mau Tambah Data Lagi
[Y/T]:');Lagi:=Upcase(Readkey);
Until Lagi<> 'Y';
{$I-};
Reset(Fileperpustakaan);
{$I+};
End;
Procedure Edit;
Var
Lagi : Char;
Ada : Boolean;
i : Integer;
NOCR: Word;
Begin
Ul :='Y';
Lagi:='Y';
Clrscr;
title;
BukaFile;
If IOResult<> 0 then
Write('Data Masih Kosong!')
Else
Begin
Repeat
Clrscr;
title;
Ada:=False;
i:=0;
x:=31;y:=6;
Gotoxy(x+2,y);Write('EDIT DATA BUKU');
Gotoxy(x+1,y+1);Write('----------------');
Gotoxy(x+4,y+2);Write('Kode Buku : ');Readln(NOCR);
While (Ada=False) And (i<>Filesize(Fileperpustakaan))
Do
Begin
Seek(Fileperpustakaan,i);
Read(Fileperpustakaan,Data);
If Data.KdBuku=NOCR Then
Begin
Ada:=True;
x:=16;y:=7;
gotoxy(X,y+2);write('SEBELUM SESUDAH');
gotoxy(x,y+3);write('-------------------------------------------');
Gotoxy(X,y+4);Write('Judul Buku : ');writeln(Data.judul);
Gotoxy(X,y+5);Write('Jenis Buku : ');writeln(Data.Jenis);
Gotoxy(X,y+6);Write('Pengarang : ');writeln(Data.Pengarang);
Gotoxy(X,y+7);Write('Penerbit : ');writeln(Data.Penerbit);
Gotoxy(X,y+8);Write('Harga Sewa : ');writeln(Data.Harga);
gotoxy(X,y+9);write('Jumlah Buku: ');writeln(Data.JBuku);
End
Else
Inc(i);
End;
If (Ada=True) Then
Begin
Data.KdBuku:=NOCR;
x:=46;y:=7;
Gotoxy(X,y+4);Write('Judul Buku : ');readln(Data.judul);
Gotoxy(X,y+5);Write('Jenis Buku : ');readln(Data.Jenis);
Gotoxy(X,y+6);Write('Pengarang : ');readln(Data.Pengarang);
Gotoxy(X,y+7);Write('Penerbit : ');readln(Data.Penerbit);
Gotoxy(X,y+8);Write('Harga Sewa : ');readln(Data.Harga);
Gotoxy (X,y+9);Write('Jumlah Buku: ');readln(Data.JBuku);
Seek(Fileperpustakaan,i);
Write(Fileperpustakaan,Data);
End
Else
Begin
Gotoxy(24,13);Write('Kode Buku "',NOCR,'" Ini
Tidak Ada!');
End;
Gotoxy(24,17);Write('Apakah Mau Edit Data Lain [Y/T]:
');Lagi:=Upcase(Readkey);
Until Lagi<>'Y';
End;
Close(Fileperpustakaan);
End;
Procedure Hapus;
Var
FileTmp : File of Perpustakaan;
Lagi,Hapus : Char;
Ada : Boolean;
i : Integer;
NOCR : Word;
Begin
Ul :='Y';
Lagi:='Y';
Clrscr;
title;
Repeat
BukaFile;
If IOResult<>0 then
Write('Data Masih Kosong!')
Else
Begin
Clrscr;
title;
Assign(FileTmp,'perpustakaan.tmp');
Rewrite(FileTmp);
Ada:=False;
i:=0;
x:=31;y:=6;
Gotoxy(x+2,y);Write('HAPUS DATA BUKU');
Gotoxy(x+1,y+1);Write('-----------------');
Gotoxy(x,y+2);Write('Kode Buku : ');Readln(NOCR);
While (Ada=False) And (i<>Filesize(FilePerpustakaan))
Do
Begin
Seek(Fileperpustakaan,i);
Read(Fileperpustakaan,Data);
If Data.KdBuku=NOCR Then
Ada:=True
Else
Inc(i);
End;
If (Ada=True) Then
Begin
Gotoxy(X,y+3);Write('Judul Buku : ');writeln(Data.judul);
Gotoxy(X,y+4);Write('Jenis Buku : ');writeln(Data.Jenis);
Gotoxy(X,y+5);Write('Pengarang : ');writeln(Data.Pengarang);
Gotoxy(X,y+6);Write('Penerbit : ');writeln(Data.Penerbit);
Gotoxy(X,y+7);Write('Harga Sewa : ');writeln(Data.Harga);
Gotoxy (X,y+8);Write('Jumlah Buku: ');writeln(Data.JBuku);
Gotoxy(x-8,y+9);Write('Apakah Data Ini Mau Di Hapus [Y/T]:
');Readln(Hapus);
If Upcase(Hapus)='Y' Then
Begin
For i := 1 to Filesize(Fileperpustakaan) Do
Begin
Seek(Fileperpustakaan,i-1);
Read(Fileperpustakaan,Data);
If Data.KdBuku<>NOCR then
Write(FileTmp,Data);
End;
Close(Fileperpustakaan);
Assign(Fileperpustakaan,'perpustakaan.txt');
Erase(Fileperpustakaan);
Assign(FileTmp,'perpustakaan.tmp');
Rename(FileTmp,'perpustakaan.txt');
Gotoxy(x-8,y+9);Write(' Nomor Buku "',NOCR,'"
Sudah Di Hapus! ');
End;
End
Else
Begin
Gotoxy(x-4,y+9);Write('Nomor Buku "',NOCR,'" Ini
Tidak Ada!');
End;
Gotoxy(x-3,y+10);Write('Mau Hapus Data Lain [Y/T]:
');Lagi:=Upcase(Readkey);
End;
Until Lagi<>'Y';
End;
Procedure Tampil;
Var
i : Integer;TBuku: integer;
Begin
clrscr;
title;
Ul :='Y';
BukaFile;
If IoResult <> 0 then
begin
gotoxy(30,11);
Write('Maaf Data Masih Kosong ! ');
end
Else
Begin
Clrscr;
title;
x:=7;y:=9;
gotoxy(x+26,y-3); write('.::DATA BUKU::.');
gotoxy(x,y-2); write(garsed2);
gotoxy(x,y-1); writeln('|No|KODE| JUDUL BUKU |JENIS BUKU|
PENGARANG | PENERBIT |HARGA |JUMLAH');
gotoxy(x,y); write(garsed2);
i:=0;
While Not EoF(Fileperpustakaan) Do
Begin
Inc(i);
Read(Fileperpustakaan,Data);TBuku:=data.JBuku+data.JBuku+data.JBuku;
Gotoxy(x,y+i); write('| ',i);
gotoxy(x+3,y+i); write('|'); writeln(data.kdbuku);
gotoxy(x+8,y+i); write('|'); writeln(data.judul);
gotoxy(x+24,y+i); write('|'); writeln(data.jenis);
gotoxy(x+35,y+i); write('|'); writeln(data.pengarang);
gotoxy(x+49,y+i); write('|'); writeln(data.penerbit);
gotoxy(x+60,y+i); write('|'); writeln(data.harga);Gotoxy
(X+67,y+i);write('|');writeln(data.JBuku:5);
gotoxy(x+77,y+i); write('|');
End;
{$I-};
Reset(Fileperpustakaan);
{$I+};
End;
Writeln;
writeln(garis2);
Write(' Tekan Enter untuk Kembali Ke menu Utama');readkey;
End;
Begin
Repeat
Menu;
Case Pil Of
'1' : Tambah;
'2' : Edit;
'3' : Hapus;
'4' : Tampil;
End;
Until (Ul<>'Y') Or (Pil='5');
DoneWincrt;
End.
Tidak ada komentar:
Posting Komentar