Selamat Datang & Terima Kasih Telah Berkunjung

Senin, 08 Oktober 2012

 SOURCE CODE


program mahasiswa;
uses crt;
type
   datasiswa = record
      npm:string[10];
      nama:string[20];
      kelas:string[10];
    end;
var
key,i,j:byte; n:integer;
temp:datasiswa; mhs:array[1..40] of datasiswa;
T:boolean;
jwb:char;

procedure npm;
    begin for i:=1 to n-1 do
         for j:=i to n do
         if mhs[i].npm>mhs[j].npm then
           begin
          temp:=mhs[i];
          mhs[i]:=mhs[j];
          mhs[j]:=temp;
          end;
    end;

 procedure nama;
     begin for i:=1 to n-1 do
           for j:=i to n do
           if mhs[i].nama>mhs[j].nama then
           begin
           temp:=mhs[i];
           mhs[i]:=mhs[j];
           mhs[j]:=temp;
           end;
     end;

  procedure kelas;
      begin
          for i:=1 to n-1 do
               for j:=i to n do
               if mhs[i].kelas>mhs[j].kelas then
               begin
               temp:=mhs[i];
               mhs[i]:=mhs[j];
               mhs[j]:=temp;
              end;
       end;

    begin
        T:=false;
        clrscr;
        write('masukkan jumlah siswa:');readln(n);
        writeln('data sebelum sorting:');
        for i:=1 to n do
        begin
         writeln('Data :',i);
         write('NPM : ');readln(mhs[i].npm);
         write('Nama mahasiswa :');readln(mhs[i].nama);
         write('Kelas :');readln(mhs[i].kelas);
         writeln;
         end;
     writeln;
    writeln('===================================================='); writeln('NPM                       NAMA                             KELAS'); writeln('====================================================');

    for i:=1 to n do
         begin
         with mhs[i] do
              begin
              write(mhs[i].npm:5);
              write(mhs[i].nama:20);
              write(mhs[i].kelas:25);
              end;
              writeln;
         end; writeln('===================================================='); writeln;

   repeat
   writeln('SORTING by :...');
   writeln('============');
   writeln('1.Npm');
   writeln('2.Nama');
   writeln('3.Kelas');
   write('press key number to continue...:');readln(key);
   writeln;

   writeln('data setelah sorting:');
   writeln;    writeln('===================================================='); writeln('NPM                 NAMA                  KELAS'); writeln('====================================================');

    if key=1 then
          begin
             npm;
          end else
    if key=2 then
          begin
              nama;
          end else
          begin
             kelas;
          end;

    for i:=1 to n do
         begin with mhs[i] do
             begin write(mhs[i].npm:5);
             write(mhs[i].nama:20);
             write(mhs[i].kelas:23);
            end;
            writeln;
        end;  writeln('==================================================='); write('Try again...[Y/T] :');readln(jwb);
until upcase(jwb)='T';
end.

 A.SORTING BERDASARKAN NAMA



B. SORTING BERDASARKAN KELAS


Tidak ada komentar:

Posting Komentar