Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

Program Search RECORD di File DAT Pada PASCAL

Berikut merupakan contoh program untuk melakukan pencarian pada PASCAL

Logika Program Searching :

Input Kode ;
xKode = kode ;
i = 1 ; ketemu = false ;
seek(file, 0) ;
while not eof(file) do
	seek(file, 0) ;
	read(file, record) ;
	if file.kode = xkode then
		ketemu = true;
		tampilkan data ;
	endif
	inc(i);
end while ;
Logika di atas dikenal juga dengan nama SEQUENTIAL SEARCH, merupakan sebuah metode di dalam pencarian data secara urut satu persatu.
Listing Program :
uses crt ;
type Produk = Record
     Kode  : String[3] ;
     Nama  : String[30] ;
     Harga : Longint ;
     End;
Var
   fPro : File of Produk ;
   rPro : Produk ;
   lg   : Char ;
   i    : byte ;
   xkode: string[8] ;
   ketemu: boolean ;

procedure openproduk ;
begin
     Assign(fpro, 'c:\produk.dat') ;
     {$I-} Reset(fpro) ;
     {$I+}if IOResult<>0 then Rewrite(fpro) ;
end;

begin
     OpenProduk ;
     Repeat
           Clrscr ;
           GotoXY(20,5) ; Write('Input Data Produk')  ;
           GotoXY(20,6) ; Write('-----------------------------')  ;
           GotoXY(20,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(20,8) ; Write('Nama  : ',rpro.Nama) ;
                    GotoXY(20,9) ; Write('Harga : ',rpro.Harga);
                    GotoXY(20,10); Write('-----------------------------')  ;
                    GotoXY(20,11); Write('Data Sudah Ada')  ;
               end;
               inc(i);
           end;

           if not ketemu then
           begin                 
                GotoXY(20,8) ; Write('Nama  : ')  ; Readln(rpro.Nama) ;
                GotoXY(20,9) ; Write('Harga : ')  ; Readln(rpro.Harga) ;
                GotoXY(20,10); Write('-----------------------------')  ;
                Seek(fpro, Filesize(fpro)) ; rpro.Kode = xkode ;
                write(fPro, rpro) ;
           end;
           GotoXY(20,12); Write('Input Lagi [Y/T] : ')  ; Readln(lg) ;
     Until Upcase(Lg)='T' ;
     close(fPro) ;
end.

Filed under: Metode-Algoritma-Teknik, Perkuliahan, ,

3 Responses

  1. hehehe…
    Ea jg…
    Good…good..

  2. ne kan pljaran yg kmaren kan pak?

Terima kasih telah memberikan komentar anda.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives Per Tahun

Sponsored

C&C Online Shop

Blog Stats

  • 355,907 sejak 12 Jan 2011

User’s Online


My Music

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 223 other followers

June 2011
M T W T F S S
« May   Jul »
 12345
6789101112
13141516171819
20212223242526
27282930  
%d bloggers like this: