Minggu, 03 Juli 2011

Program Searching

uses wincrt;
type dokter=record
     kode         :string[3];
     nama         :string[20];
     specialis    :string[20];
     end;

var
   fdok         :file of dokter;
   rdok         :dokter;
   i            :byte;
   xkd          :string[3];
   lg           :char;
   ketemu       :Boolean;

procedure opendokter;
begin
     clrscr;
    assign(fdok,'c:\dokterr.dat');
    {$I-} reset (fdok);
    {$I+} if ioresult<>0 then rewrite(fdok);
end;

begin
    clrscr;
    opendokter;
    repeat
         i:=1;
         ketemu:=false;
         gotoxy(40,3);write('kode:');readln(xkd);
         seek (fdok,0);
         while not eof(fdok) do
         begin
             seek (fdok,i-1);read(fdok,rdok);
             if rdok.kode=xkd then
             begin
                 gotoxy(40,4);write('nama:',rdok.nama);
                 gotoxy(40,5);write('specialis:',rdok.specialis);
                 ketemu:=true;
             end;
             inc(i);
         end;
         rdok.kode:=xkd;
         if not ketemu then
         begin
             gotoxy(40,8);write('nama:');readln(rdok.nama);
             gotoxy(40,9);write('specialis:');readln(rdok.specialis);
             seek (fdok,filesize(fdok));
             write(fdok,rdok);
         end;
         gotoxy(40,10);write('input lagi[Y/T]:');readln(lg);
    until upcase(lg)='T';
    close(fdok);
end.