Cari Blog Ini

Rabu, 09 November 2011

Tugas SOD Program Sortir dan Update data mahasiswa

Program Mahasiswa;
uses crt;
label 1;
type
DMHS = record
            NPM : String;
            Nama : String;
            KELAS : string;
        end;
var
List : array [1..15] of DMHS;
i, h, j, n, pil, m : integer;
NPM1 : String;
temp : DMHS;

procedure insert;
begin
inc(i);
inc(n);
gotoxy(6,16); write('Masukkan Data Mahasiswa');
gotoxy(6,18); write('NMP 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
k : integer;
ketemu : boolean;
begin
k := 1;
ketemu := false;
while (not ketemu) and (k <= n) do
if List[k].NPM = z then
ketemu := true
else
k := k + 1;
if ketemu 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[k].NPM);
gotoxy(33,21); writeln(List[k].Nama);
gotoxy(55,21); writeln(List[k].KELAS);
gotoxy(18,22); writeln('|___________|____________________|_________|');
end
else
begin
gotoxy(20,15); write('Mahasiswa Dengan NPM ',z,' : Tidak Ditemukan');
end;
end;

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

Hasil mengimput data mahasiswa :                                            





















  Output setelah di sortir  : 













Output Saat data di update :














Output setelah di update :