Codingnya :
PROGRAM Tugas_Sorting_Data_Mahasiswa;
USES CR T;
CONST
garis='------------------------------------------------------';
VAR
kelas : ARRAY [1..100] OF STRING[5];
npm : ARRAY [1..100] OF STRING[8];
nama : ARRAY [1..100] OF STRING[15];
n,i,bar,kelompok,tempatnya_min,pil : INTEGER;
min, temp : STRING;
label menu;
label exit;
BEGIN
CLRSCR;
WRITE('Jumlah Data Mahasiswa : ');
READLN(N);
FOR i:= 1 TO n DO
BEGIN
CLRSCR;
WRITELN('Data Ke- ',i:2);
WRITE('NPM : '); READLN(NPM[i]);
WRITE('Nama : '); READLN(NAMA[i]);
WRITE('Kelas : '); READLN(KELAS[i]);
END;
menu:
clrscr;
writeln('Choice: ');
writeln('1.Sort by Class');
writeln('2.Sort by Name');
writeln('3.Exit');
write('Select Number: ');readln(pil);
case pil of
1:FOR kelompok := 1 TO n DO
BEGIN
min := KELAS[kelompok];
FOR i := kelompok TO n DO
BEGIN
IF (KELAS[i] <= min) THEN
BEGIN
min := KELAS[i];
tempatnya_min := i;
END;
END;
temp := KELAS[kelompok];
KELAS[kelompok] := KELAS[tempatnya_min];
KELAS[tempatnya_min] := temp;
temp := NPM[kelompok];
NPM[kelompok] := NPM[tempatnya_min];
NPM[tempatnya_min] := temp;
temp := NAMA[kelompok];
NAMA[kelompok] := NAMA[tempatnya_min];
NAMA[tempatnya_min] := temp;
END;
2:FOR kelompok := 1 TO n DO
BEGIN
min := NAMA[kelompok];
FOR i := kelompok TO n DO
BEGIN
IF (NAMA[i] <= min) THEN
BEGIN
min := NAMA[i];
tempatnya_min := i;
END;
END;
temp := KELAS[kelompok];
KELAS[kelompok] := KELAS[tempatnya_min];
KELAS[tempatnya_min] := temp;
temp := NPM[kelompok];
NPM[kelompok] := NPM[tempatnya_min];
NPM[tempatnya_min] := temp;
temp := NAMA[kelompok];
NAMA[kelompok] := NAMA[tempatnya_min];
NAMA[tempatnya_min] := temp;
END;
3:goto exit;
end;
CLRSCR;
GOTOXY(5,4); WRITE(GARIS);
GOTOXY(5,5); WRITE('NO');
GOTOXY(9,5); WRITE('NPM');
GOTOXY(20,5); WRITE('NAMA');
GOTOXY(37,5); WRITE('KELAS');
GOTOXY(47,5); WRITE('PARAF');
GOTOXY(5,6); WRITE(GARIS);
bar:=7;
FOR i:= 1 TO n DO
BEGIN
GOTOXY(5,bar); WRITELN(i:2);
GOTOXY(9,bar); WRITELN(NPM[i]);
GOTOXY(20,bar); WRITELN(NAMA[i]);
GOTOXY(37,bar); WRITELN(KELAS[i]);
GOTOXY(47,bar); WRITELN(i,'. . .');
bar:=bar+1;
END;
GOTOXY(5,bar+1);WRITELN(garis);
READLN;
goto menu;
exit:
END.
end;
CLRSCR;
GOTOXY(5,4); WRITE(GARIS);
GOTOXY(5,5); WRITE('NO');
GOTOXY(9,5); WRITE('NPM');
GOTOXY(20,5); WRITE('NAMA');
GOTOXY(37,5); WRITE('KELAS');
GOTOXY(47,5); WRITE('PARAF');
GOTOXY(5,6); WRITE(GARIS);
bar:=7;
FOR i:= 1 TO n DO
BEGIN
GOTOXY(5,bar); WRITELN(i:2);
GOTOXY(9,bar); WRITELN(NPM[i]);
GOTOXY(20,bar); WRITELN(NAMA[i]);
GOTOXY(37,bar); WRITELN(KELAS[i]);
GOTOXY(47,bar); WRITELN(i,'. . .');
bar:=bar+1;
END;
GOTOXY(5,bar+1);WRITELN(garis);
READLN;
goto menu;
exit:
END.
0 komentar:
Posting Komentar