Senin, 14 November 2011

Program update dan sorting pascal

ini adalah contoh codingan program pascal sort data dan update : 
Program Mahasiswa;
         uses crt;
         label 1;
         type
              DMHS = record
              Nama : String;
              NPM : String;
              Kelas :string;
              end;
         var
              List : array [1..100] of DMHS;
              i, h, j, n, pil, m, a : integer;
              NPM1 : String;
              temp : DMHS;
              z : string;

procedure insert;
begin
inc(i);
inc(n);
gotoxy(6,16); write('Masukkan Data Mahasiswa');
gotoxy(6,18); write('NPM Mahasiswa : '); readln(List[i].NPM);
gotoxy(6,19); write('Nama Mahasiswa : '); readln(List[i].Nama);
gotoxy(6,20); write('Kelas Mahasiswa : '); readln(List[i].KELAS);
end;

procedure cari(z : String);
var
i : integer;
berhasil : boolean;
begin
i := 1;
berhasil := false;
while (not berhasil) and (i <= n) do
if List[i].NPM = z then
berhasil := true
else
i := i + 1;
if berhasil then

begin
gotoxy(21,15); write('Mahasiswa Dengan NPM ',z,' : Ditemukan');
gotoxy(18,17); writeln('|¯¯¯¯¯¯¯¯¯¯¯|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|¯¯¯¯¯¯¯¯¯¯¯|');
gotoxy(18,18); writeln('|    NPM    |        NAMA        |   KELAS   ;');
gotoxy(18,19); writeln('|___________|____________________|___________|');
gotoxy(18,20); writeln('|           |                    |           |');
gotoxy(18,21); writeln('|           |                    |           |');
gotoxy(20,21); writeln(List[i].NPM);
gotoxy(33,21); writeln(List[i].Nama);
gotoxy(55,21); writeln(List[i].KELAS);
gotoxy(18,22); writeln('|___________|____________________|___________|');
end
else
begin
gotoxy(21,15); write('Mahasiswa Dengan NPM ',z,' : Tidak Ditemukan');
end;
end;

procedure update(p : String);
var
x, y, z : String;
q, o : integer;
berhasil : boolean;
begin
q := 1;
if (NPM1 = '0') or (NPM1 = '') then
begin
gotoxy(15,20); write('Masukkan NPM yang Benar');
end
else
begin
berhasil := false;
while (not berhasil) and (q <= n) do
if List[q].NPM = p then
berhasil := true
else

q := q + 1;
if berhasil then
begin
gotoxy(5,21); write('Data Yang Akan di Update : ');
gotoxy(5,20); write('1. NPM 2. Nama 3. Kelas');
gotoxy(33,21); readln(pil);
case pil of

1 : begin
gotoxy(5,23); write('Masukkan NPM yang Baru : ');
readln(x);
List[q].NPM := x;
end;

2 : begin
gotoxy(5,23); write('Masukkan Nama yang Baru : ');
readln(y);
List[q].Nama := y;
end;

3 : begin
gotoxy(5,23); write('Masukkan Kelas yang Baru : ');
readln(z);
List[q].KELAS := z;
end;
end;
end
else

begin
gotoxy(5,22); write('NPM ',p,' Tidak Terdapat Dalam Daftar');

end;
end;
end;

procedure cetak;
begin
if m = 2 then
begin
gotoxy(37,2); write('Tabel Nilai Mahasiswa Setelah Diurutkan');
end
else if m = 0 then
begin
gotoxy(47,2); write('Tabel Nilai Mahasiswa');
end;
gotoxy(35,4); writeln  ('|¯¯¯¯¯¯¯¯¯¯¯|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|¯¯¯¯¯¯¯¯¯¯|');
gotoxy(35,5); writeln  ('|    NPM    |       NAMA         |  KELAS   |');
gotoxy(35,6); writeln  ('|___________|____________________|__________|');
gotoxy(35,7); writeln  ('|           |                    |          |');
gotoxy(35,8+n); writeln('|___________|____________________|__________|');
for j := 1 to n do
begin
gotoxy(35,7+j); writeln('|           |                    |          |');
gotoxy(37,7+j); writeln(List[j].NPM);
gotoxy(50,7+j); writeln(List[j].Nama);
gotoxy(72,7+j); writeln(List[j].KELAS);
end;
end;

begin { Program Utama }
i := 0;
n := 0;
repeat
1 : clrscr;
m := 0;
gotoxy(3,2); writeln ('|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|');
gotoxy(3,3); writeln ('|      Menu     |');
gotoxy(3,4); writeln ('|               |');
gotoxy(3,5); writeln ('|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|');
gotoxy(3,6); writeln ('|   1. Insert   |');
gotoxy(3,7); writeln ('|   2. Urutkan  |');
gotoxy(3,8); writeln ('|   3. Cari MHS |');
gotoxy(3,9); writeln ('|   4. Update   |');
gotoxy(3,10); writeln('|   5. Exit     |');
gotoxy(3,11); writeln('|               |');
gotoxy(3,12); writeln('|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|');
gotoxy(3,13); writeln('|  Pilihan :    |');
gotoxy(3,14); writeln('|_______________|');
cetak;
gotoxy(16,13); readln (pil);
case pil of
1 : begin
m := 0;
insert;
end;
2 : begin
repeat
clrscr;
gotoxy(3,2); writeln ('|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|');
gotoxy(3,3); writeln ('|      Menu     |');
gotoxy(3,4); writeln ('|               |');
gotoxy(3,5); writeln ('|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|');
gotoxy(3,6); writeln ('|   1. NPM      |');
gotoxy(3,7); writeln ('|   2. Nama     |');
gotoxy(3,8); writeln ('|   3. Kelas    |');
gotoxy(3,9); writeln ('|   4. Menu     |');
gotoxy(3,10); writeln('|   5. Exit     |');
gotoxy(3,11); writeln('|               |');
gotoxy(3,12); writeln('|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|');
gotoxy(3,13); writeln('|   Pilihan:    |');
gotoxy(3,14); writeln('|_______________|');

cetak;
gotoxy(16,13); readln(pil);
m := 2;
case pil of
1 : begin
for h := 1 to n-1 do
for j := 1 to n-1 do
if List[j].NPM > List[j+1].NPM then

begin
temp := List[j];
List[j] := List[j+1];
List[j+1] := temp;
end;
end;
2 : begin
for h := 1 to n-1 do
for j := 1 to n-1 do
if List[j].Nama > List[j+1].Nama then

begin
temp := List[j];
List[j] := List[j+1];
List[j+1] := temp;
end;
end;
3 : begin
for h := 1 to n-1 do
for j := 1 to n-1 do
if List[j].KELAS > List[j+1].KELAS then

begin
temp := List[j];
List[j] := List[j+1];
List[j+1] := temp;
end;
end;
4 : begin
goto 1;
end;
end;
cetak;
until
pil >= 5;
end;
3 : begin
gotoxy(21,15); write('NPM Mahasiswa yang akan dicari : ');
readln(NPM1);
cari(NPM1);
gotoxy(18,24); write('Tekan Sembarang Tombol Untuk Kembali Ke Menu');
end;

4 : begin
gotoxy(5,18); write('NPM Mahasiswa Yang Akan di Update : ');
readln(NPM1);
update(NPM1);
end;
end;
until pil >= 5;
end.

ini adalah tampilan/ouput  dari program diatas