PROGRAM PASCAL UNTUK MENENTUKAN KUNCI YANG DICARI Ozhora97 4/07/2018 Ozhora97 Program Pascal : program sb_tgs3_v02; uses crt; const max=100; type ang=array[1..max] of integer; var pil:0..3; jum,i,j:integer; nilai,nilai_urut:ang; yete:string; label ulang; procedure E_en_de(); begin writeln(' |===================================|'); writeln(' | *** TERIMAKASIH *** |'); writeln(' |===================================|'); end; procedure input_nilai(var x:ang); var str_jum,str_nil,pil:string; cek:integer; label ulang,ulang2,akhir; begin ulang: clrscr; writeln; writeln(' |========================================|'); writeln(' | *** INPUT DATA KUNCI *** |'); writeln(' |========================================|'); writeln; write(' Masukkan Jumlah Kunci : ');readln(str_jum); val(str_jum,jum,cek); if (cek=0) then begin if (jum<0) then begin writeln; writeln('Inputan Tidak Boleh Selain Bilangan Bulat Positif !'); writeln; write('Input Data Lagi (y/t) ? ');readln(pil); if (pil='y') or (pil='Y') then goto ulang else E_en_de(); end else begin writeln; for i:=1 to jum do begin ulang2: write('Masukkan Nilai Kunci Ke-',i,' : ');readln(str_nil); val(str_nil,nilai[i],cek); if (cek<>0) then begin writeln; writeln('Inputan Tidak Boleh Selain Bilangan Bulat !'); writeln; write('Lanjut Input Data (y/t)? ');readln(pil); if (pil='y') or (pil='Y') then goto ulang2 else begin E_en_de(); goto akhir; end; end; end; nilai_urut:=nilai; end; end else begin writeln('Inputan Tidak Boleh Selain Bilangan Bulat Positif !'); writeln; write('Input Data Lagi (y/t) ? ');readln(pil); if (pil='y') or (pil='Y') then goto ulang else E_en_de(); end; akhir: end; procedure cetak(var x:ang); begin write(' ==========='); for i:=1 to jum do write('======='); writeln; write(' | Data Ke |'); for i:=1 to jum do write(i:6,'|'); writeln; write(' ==========='); for i:=1 to jum do write('======='); writeln; write(' | Nilai |'); for i:=1 to jum do write(x[i]:6,'|'); writeln; write(' ==========='); for i:=1 to jum do write('======='); writeln; end; procedure cetak_data(var x:ang); var urut:boolean; tampung:integer; begin clrscr; urut:=true; writeln; writeln(' |========================================|'); writeln(' | *** CETAK DATA KUNCI *** |'); writeln(' |========================================|'); writeln; //Cetak Data Nilai cetak(nilai); for i:=1 to jum do for j:=i+1 to jum do begin if nilai_urut[i]>=nilai_urut[j] then begin urut:=false; tampung:=nilai_urut[j]; nilai_urut[j]:=nilai_urut[i]; nilai_urut[i]:=tampung; end end; if urut then writeln(' *** Data Nilai Kunci Sudah Berurutan ***') else begin writeln; writeln(' *** Data Nilai Kunci Belum Berurutan ***'); writeln; writeln(' Kunci Berurutan :'); writeln; cetak(nilai_urut); end; end; procedure cari_kunci(var x:ang); var str_cari,pil:string; cek,cari,tengah,awal,akhir,y:integer; nil_awal,nil_tengah,nil_akhir:double; car:boolean; label ulang; begin ulang: car:=true; clrscr; writeln; writeln(' |=========================================|'); writeln(' | *** CARI DATA KUNCI *** |'); writeln(' |=========================================|'); writeln; cetak(nilai_urut); writeln; write(' Masukkan Kunci Yang Dicari : ');readln(str_cari); val(str_cari,cari,cek); if (cek=0) then begin awal:=1;akhir:=jum; nil_awal:=nilai_urut[1]; nil_akhir:=nilai_urut[jum]; if (jum mod 2 = 0) then begin writeln('Maaf Belum Ketemu Rumusnya :)'); car:=false; end else begin tengah:=Trunc(jum/2+1); nil_tengah:=nilai_urut[tengah]; end; y:=1; while (car) do begin writeln; writeln('Langkah Ke-',y); writeln('==============================================='); writeln(' Awal Akhir Tengah Nilai '); write(' ',awal:7,' ',akhir:7,' ',tengah:7,' ',nil_tengah:7:1); writeln; writeln('==============================================='); writeln; if (nil_tengah=cari) then begin writeln('Kunci Ditemukan Pada Langkah Ke-',y); writeln('Kunci Ditemukan Pada Urutan Ke-',tengah); writeln('Waktu Pencarian : Belum tau'); car:=false; end else if (nil_tengahcari) then begin awal:=awal; akhir:=tengah-1; if (awal=akhir) then tengah:=akhir else tengah:=Trunc(((akhir-awal)/2)+awal); nil_tengah:=nilai_urut[tengah]; car:=true; end; inc(y); if (y=10) then car:=false; end; end else begin writeln; writeln('Inputan Tidak Boleh Selain Bilangan Bulat !'); writeln; write('Lanjut Cari Kunci (y/t)? ');readln(pil); if (pil='y') or (pil='Y') then goto ulang else begin E_en_de(); end; end; end; begin jum:=0; repeat; ulang: clrscr; writeln('|=========================================================|'); writeln('| 151051038 |'); writeln('| RAHMAT KHOIRUN NIAM |'); writeln('|=========================================================|'); writeln; writeln('|=========================================================|'); writeln('| TUGAS 3 SISTEM BERKAS |'); writeln('| PILIHAN MENU |'); writeln('|=========================================================|'); writeln('| 1. | Input Data Kunci |'); writeln('| 2. | Cetak Data Kunci |'); writeln('| 3. | Cari Kunci |'); writeln('| 0. | Keluar |'); writeln('|=========================================================|'); write(' Masukkan Pilihan Menu :');readln(pil); case pil of 1: if (jum<>0) then begin write('Apakah Anda Ingin Mengganti Data Yang Sudah Ada (y/t) ? ');readln(yete); if (yete='y') or (yete='Y') then begin input_nilai(nilai); end else goto ulang; end else begin writeln('Input Dara Baru'); input_nilai(nilai); end; 2: if jum<=0 then writeln('Data Masih Kosong') else cetak_data(nilai); 3: if jum<=0 then writeln('Data Masih Kosong') else cari_kunci(nilai); 0: E_en_de(); end; readln; until pil=0; end. Screenshoot : sds Tweet Share Share Share Share About Admin Jangan menyerah atas impianmu, impian memberimu tujuan hidup. Ingatlah, sukses bukan kunci kebahagiaan, kebahagiaan adalah kunci kesuksesan. Semangat!! Jangan lupa bahagia. Related Post
ConversionConversion EmoticonEmoticon