Selasa, 08 November 2011

Program Sortir Data Mahasiswa

program sort_DATA_MAHASISWA;
uses crt;
type
    dataMHS=string;
var
    nama,NPM,kelas: array[1..15] of dataMHS;
    z,a,n: byte;
    temp: string;
const garis='================================';
begin
    clrscr;
    write('masukkan data:');readln(n);
    writeln('data awal:');
    for z:= 1 to n do
     begin
        write('nama:');readln(nama[z]);
        write('NPM:');readln(NPM[z]);
        write('kelas:');readln(kelas[z]);
        writeln;
     end;
    for z:=1 to n-1 do
begin
    for a:=z to n do
    begin
    if (kelas[a] < kelas[z]) then
    begin
     temp := nama[a];
     nama[a] := nama[z];
     nama[z] := temp;
     temp := NPM[a];
     NPM[a] := NPM[z];
     NPM[z] := temp;
     temp := kelas[a];
     kelas[a] := kelas[z];
     kelas[z] := temp;
    end;
    end;
end;
    writeln;
    writeln('setelah diurutkan:');
    for z:= 1 to n do
begin
    writeln;
    writeln('DATA MAHASISWA');
    writeln;
    writeln(garis);
    writeln('nama        NPM          kelas');
    writeln(garis);
    for z:= 1 to n do
    begin
        writeln(nama[z]:0,NPM[z]:16,kelas[z]:9);
    end;
end;
readln
end.