Neh codingannya gan :
PROGRAM Tugas_table_n_sorting;
USES CRT;
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,j,bar,kelompok,tempatnya_min,x : INTEGER;
min, temp : STRING;
LABEL INPUT,MENU,CETAK,SELESAI;
BEGIN
CLRSCR;
{ pemasukan data dalam array }
INPUT:
WRITE('MAU ISI BERAPA DATA : ');
READLN(N);
FOR i:= 1 TO n DO
BEGIN
CLRSCR;
GOTOXY(30,4); WRITE('DATA KE- ',i:2);
GOTOXY(10,7); WRITE('NPM : '); READLN(NPM[i]);
GOTOXY(10,8); WRITE('NAMA : '); READLN(NAMA[i]);
GOTOXY(10,9); WRITE('KELAS : '); READLN(KELAS[i]);
END;
GOTO CETAK;
{ pilih menu }
MENU:
WRITELN('1) Sort by NAMA.');
WRITELN('2) Sort by KELAS.');
WRITELN('3) Sort by NPM.');
WRITELN('4) Exit.');
WRITE('PILIH = ');READLN(x);
case x of
1: begin
for i := n - 1 downto 1 do
for j := 1 to i do
if nama[j] > nama[j+1] then
begin
temp := kelas[j];
kelas[j] := kelas [j+1];
kelas[j+1] := temp;
temp := npm[j];
npm[j] := npm [j+1];
npm[j+1] := temp;
temp := nama[j];
nama[j] := nama [j+1];
nama[j+1] := temp;
end;
end;
2: begin
for i := n - 1 downto 1 do
for j := 1 to i do
if kelas[j] > kelas[j+1] then
begin
temp := kelas[j];
kelas[j] := kelas [j+1];
kelas[j+1] := temp;
temp := npm[j];
npm[j] := npm [j+1];
npm[j+1] := temp;
temp := nama[j];
nama[j] := nama [j+1];
nama[j+1] := temp;
end;
end;
3: begin
for i := n - 1 downto 1 do
for j := 1 to i do
if npm[j] > npm[j+1] then
begin
temp := kelas[j];
kelas[j] := kelas [j+1];
kelas[j+1] := temp;
temp := npm[j];
npm[j] := npm [j+1];
npm[j+1] := temp;
temp := nama[j];
nama[j] := nama [j+1];
nama[j+1] := temp;
end;
end;
4: begin
goto selesai;
end;
end;
{ cetak atas absen }
CETAK:
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);
{ proses Cetak isi array di absen }
bar:=7;
FOR i:= 1 TO n DO
BEGIN
{ penempatan cetak array }
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;
SELESAI:
END.
program diatas menggunakan type sorting bubble sort, silahkan di coba gan, semoga berhasil dan bermanfaat buat kita semua,.. ^^
0 komentar:
Posting Komentar
Terima kasih atas kunjungannya ke blog saya.