Senin, 30 Maret 2015

Contoh Proogram Selection Sort Data Mahasiswa pada Pascal

Berikut contoh program pengurutan nilai IPK pada data mahasiswa

uses crt;
type mhs= record
     Nama, NIM: string;
     IPK : real;
end;
var Data : array [1..100] of mhs;
    i, j, n, temp : integer;
    pilih : char;

procedure input;
begin
clrscr;
write('Masukkan jumlah mahasiswa : ');
readln(n);
for i := 1 to n do
begin
  writeln(' ___________________________________');
  writeln('|        Data Mahasiswa Ke-',i,'        |');
  writeln('|-----------------------------------|');
  writeln('| Nama    :                         |');
  writeln('| NIM     :                         |');
  writeln('| IPK     :                         |');
  writeln('|___________________________________|');
  gotoxy(13,5+(7*(i-1)));readln(Data[i].Nama);
  gotoxy(13,6+(7*(i-1)));readln(Data[i].NIM);
  gotoxy(13,7+(7*(i-1)));readln(Data[i].IPK);
  writeln;
 end;
end;

Procedure Table;
Begin
  writeln('|    |                          |           |           |');
  writeln('|____|__________________________|___________|___________|');
end;


procedure Tampil;
begin
clrscr;
 writeln(' _______________________________________________________');
 writeln('|                                                       |');
 writeln('|                 DATA NILAI MAHASISWA                  |');
 writeln('|_______________________________________________________|');
 writeln('|    |                          |           |           |');
 writeln('| No |         Nama             |    NIM    |    IPK    |');
 writeln('|____|__________________________|___________|___________|');
for i:=1 to n do
begin
 gotoxy(1,7+i);Table;
 gotoxy(3,7+i);writeln(i);
 gotoxy(8,7+i);writeln(Data[i].Nama);
 gotoxy(35,7+i);writeln(Data[i].NIM);
 gotoxy(50,7+i);writeln(Data[i].IPK:2:0);
 end;
readkey;
end;

procedure Selection;
var max: integer;
temp: mhs;
begin
 for i:=1 to n-1 do
  begin
   max:=i;
   for j:= i+1 to n do
    if Data[j].IPK< Data[max].IPK then
    max:=j;
    temp:= Data[max];
    Data[max]:= Data[i];
  Data[i]:= temp;
  end;
Tampil;
end;

begin
input;
Selection;
end.

Screenshot


0 komentar:

Posting Komentar

sealkazzsoftware.blogspot.com resepkuekeringku.com