Program Mahasiswa Sederhana dengan Menggunakan di array.

Sebuah program sederhana sebagai contoh implementasi algoritma pencarian biner(binary search)
dan algoritma pengurutan.


program UTS_program_mahassiswa_punya_Hendri;

uses wincrt; {memakai pascal untuk windows}



const m = 14;





type data_mhs = record

 nim : longint;

 nama_mhs : string;

 jur  : string;

 end;

larik = array[1..m] of data_mhs;





var



 pil:integer;

 l:larik;

 x:longint;

 idx:integer;









 procedure judul;

 begin

 writeln('+++Created By Hendri+++');

 writeln('=-=-=-=-=-=-=-=-=-=-=-=');

 writeln('original varsion+*+*                                                   (^_^)7');









 end;







 {.............................................................................procedre pengurutan}

 procedure pengurutan_data(var l : larik; m : integer) ;



 var

 i : integer;

 j : integer;

 x : longint;

 ketemu : boolean;

 begin

 for i:=2 to m do

 begin

 x:=l[i].nim;

 j:=i-1;

 ketemu:=false;

 while (j >= 1) and (not ketemu) do

 begin

 if x < l[j].nim then

 begin

 l[j+1].nim:=l[j].nim;

 j:=j-1;

 end else

 ketemu:=true;

 end;

 l[j+1].nim:=x;

 end;

 end;



 {..............................................................................Procedure pencarian}

 procedure pencarian_data(l : larik; m:integer; x:longint; var idx :integer);





 var

 i,j : integer;

 k : integer;

 ketemu : boolean;



 begin

 i:=1;

 j:=m;

 ketemu:=false;



 while (not ketemu) and (i <= j) do

 begin

 k:=(i+j)div 2;

 if (l[k].nim = x) then

 ketemu:=true

 else



 if (l[k].nim > x) then

 i:=k+1

 else

 j:=k-1;



 end;

 if (ketemu) then

 idx:=k

 else

 idx:=0;





 end;



 {.................................................................................procedure isi data}

 procedure isi_data(var l : larik; m : integer);



 var



 i : integer;

 tanya:char;





 j : integer;

 x : string;

 t : boolean;



 begin

 clrscr;

 judul;

 t:=true;



 i:=1;

 while t do

 begin

 writeln('            ');

 writeln    ('               MENU ISI DATA MAHASISWA       ');

 write('');

 writeln('            ============================');

 write  ('             nim     :');readln(l[i].nim);

 write  ('             Nama    :');readln(l[i].nama_mhs);

 write  ('             Jurusan :');readln(l[i].jur);

 writeln('            ============================');

 i:=i+1;

 if i>m then

 begin

 write('tekan "m" untuk untuk kembali ke menu utama:');readln(tanya);



 exit;

 end;





 writeln('            ****************************');

 write('             mau isi lagikah...???[y/t]');readln(tanya);



 writeln('            ............................');





 if tanya='t'then

 begin

 t:=false

 end;





 end;



 pengurutan_data(l, m) ;









 end;



 {...................................................................................procedure edit data}

 procedure edit_data( m : integer;var l: larik;  idx: integer);





 var

 x : longint;

 t:boolean;

 tanya : char;

 begin



 t:=true;

 while t=true do

 begin

 clrscr;

 judul;

 writeln('                *************MENU EDIT DATA*************');

 writeln('       --------------------------------------------------------');

 writeln('       ========================================================');

 write  ('           masukan nim mahasiswa yang ingin di edit:');readln(x);

 writeln('       ========================================================');

 pengurutan_data(l, m) ;



 pencarian_data(l,m, x,idx);

 if idx=0 then

 begin

 writeln('');

 write('         maaf nomor induk mahasiswa ',x,' balum ada.... silahkan coba lagi') ;

 writeln('') ;

 writeln('')   ;

 writeln('     ========================================================================')

 end

 else

 begin

 writeln('                  nim     :',l[idx].nim);

 writeln('                  nama    :',l[idx].nama_mhs);

 writeln('                  jurusan :',l[idx].jur);

 writeln('                ==============================');

 end;

 write('apakah nim ',x,' mau di isi atau di rubah??[y/t atau ke menu utama(k)]:');readln(tanya);

 if tanya='t' then

 begin

 t:=false;



 end;



 end;

 if tanya='y' then

 begin

 if idx=0 then

 begin

 idx:=idx+1;

 end;

 writeln('          ========================================================');

 l[idx].nim:=x;

 writeln('               nim     :',x);

 write  ('               Nama    :');readln(l[idx].nama_mhs);

 write  ('               Jurusan :');readln(l[idx].jur);

 end

 else if tanya='k' then

 begin

 exit;



 end;

 end;





 {...........................................................................................procedure tempat data}

 procedure tempat_data(idx: integer; var l: larik; m : integer);



 var

 x : longint ;

 tanya:char;

 begin

 tanya:='y';

 while tanya='y' do

 begin

 clrscr;

 judul;

 writeln('');

 writeln('');

 writeln('             PROCEDURE MENCARI TEMPAT DATA');

 writeln('      --------------------------------------------------');

 write('              masukan nim mahasiswa :');readln(x);

 writeln('      ==================================================');

 pengurutan_data(l, m) ;

 pencarian_data(l,m, x,idx);

 writeln('        posisi data ada pada nomor larik :',idx);

 write('        mau cari tempat data lagikah??[y/t] :');readln(tanya);

 end;

 end;





 {..............................................................................................procedure cari data}

 Procedure cari_data( m : integer; var l: larik; idx: integer);



 var

 x : longint;

 tanya : char;

 begin



 tanya:='y';

 while tanya='y' do

 begin

 clrscr;

 judul;

 writeln('              *************MENU MENCARI DATA*************');

 writeln('       ---------------------------------------------------------');

 writeln('       -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');

 write  ('           masukan nomor induk mahasiswa yang di cari:');readln(x);

 writeln('       TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT');

 writeln('              ');

 pengurutan_data(l, m) ;



 pencarian_data(l,m, x,idx);

 if idx=0 then

 begin

 writeln('');

 write('         maaf nomor induk mahasiswa ',x,' balum ada.... silahkan coba lagi') ;

 writeln('') ;

 writeln('')   ;

 writeln('     ========================================================================')

 end

 else

 begin

 writeln('                  nim     :',l[idx].nim);

 writeln('                  nama    :',l[idx].nama_mhs);

 writeln('                  jurusan :',l[idx].jur);

 writeln('                ==============================');

 end;

 write('              Mau mencoba nomor mahasiswa yang lainkah??[y/t]:');readln(tanya);



 end;



 end;







 Procedure tutup;



 begin

 clrscr;





 writeln('');

 writeln('');

 writeln('');

writeln('             ##############################################################');delay;

writeln('             #************************************************************#');delay;

writeln('             #*                                                      *****#');delay;

writeln('             #*    DI BUAT OLEH :                                   ******#');delay;

writeln('             #*                      HENDRI KARISMA                *******#');delay;

writeln('             #*                         10107352                 *********#');delay;

writeln('             #*********            -==================-        ***********#');delay;

writeln('             #********                                                   *#');delay;

writeln('             #******                TEKNIK INFORMATIKA                   *#');delay;

writeln('             #*****           --------------------------------           *#');delay;

writeln('             #****             UNIVERSITAS KOMPUTER INDONESIA            *#');delay;

writeln('             #***                         2008                           *#');delay;

writeln('             #************************************************************#');delay;

writeln('             ##############################################################');delay;



 exit;



 end;







 { ================================================================================================procedure menu}

 procedure menu_utama(pil:integer);



 var

 i:integer;

 x:longint;



 begin



 while (pil<>5) do

 begin

 clrscr;

 judul;

 writeln('');

 writeln('');

 writeln('             (====================================)') ; delay;

 writeln('             ( M  E  N  U    P  R  O  G  R  A  M  )'); delay;

 writeln('             (====================================)');delay;

 writeln('             (Data Mahasiswa                      )'); delay;

 writeln('             (--------------                      ) ');delay;

 WRITELN('             (      1. Isi Data Mahsiswa          )'); delay;

 writeln('             (      2. Edit Data Mahasiswa        )'); delay;

 writeln('             (      3. Cari Data Mahasiswa        )'); delay;

 writeln('             (      4. Mencari Tempat Data        )'); delay;

 writeln('             (                                    )'); delay;

 writeln('             (      5. Keluar                     )'); delay;

 writeln('             (                                    ) ');delay;



 writeln('             ====================================== ');delay;

 gotoxy(1,20);writeln('             ====================================== '); delay;

 gotoxy(1,19);write  ('                masukan pilihan menu :');readln(pil);writeln('  = ');delay;





 writeln('');

 writeln('');

 writeln('');



 writeln('');

 writeln('');



 if pil=1 then

 begin

 isi_data(l,m);

 end

 else if pil=2 then

 begin

 edit_data(m,l,idx);

 end

 else if pil=3 then

 begin



 cari_data(m,l,idx);

 end





 else if pil=4 then

 begin

 tempat_data(idx,l, m);



 end





 else if (pil>5) or (pil<=0) then

 begin

 write('maaf pilihan hanya 1-5.... silahkan pilih kembali');

 end;



 end;



 tutup;

 end;





 { =============================================================================================================algo utama}



begin

//pembuka;//sebenernya ada prosedur pembuka tp takut pusing liatnya...

 menu_utama(pil);





 gotoxy(32,20);write('BYE..........BYE........');



end.

sebenarnya kode ini belum lengkap hehehe...

Advertisements

Leave a Reply

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