- Nama : Program Pengurutan Berdasarkan IPK dengan Selection Sort
- Bahasa : Pascal
- Software : Free Pascal IDE
- Deskripsi : Program ini menggunakan selection sort untuk mengurutkan data berdasarkan IPK. Pertama-tama user akan menginputkan data berupa nama dan IPK sebanyak yang diinginkan user. Kemudian program akan men-sorting IPK dari yang terkecil sampai terbesar dan kemudian meng-output-kannya.
- Screenshot :Gambar 1. Penginputan jumlah data
- Tabel Proses Sorting :
Data awal
|
3.8
|
2.9
|
3.5
|
3.1
|
3.4
|
Swap ke-1
|
3.8
|
3.5
|
2.9
|
3.1
|
3.4
|
Swap ke-2
|
3.8
|
3.5
|
3.4
|
3.1
|
2.9
|
Data akhir
|
3.8
|
3.5
|
3.4
|
3.1
|
2.9
|
- Source Code :
uses crt;
type
mhs =record
nama
:string;
nim :string;
ipk :real;
end;
amhs =array[1..10] of mhs;
var
dtmhs :amhs;
jlh_mhs,a:byte;
procedure swap(var i,j:real);
var
temp :real;
begin
temp:=j;
j :=i;
i :=temp;
end;
procedure swap2(var i,j:string);
var
temp :string;
begin
temp:=j;
j :=i;
i :=temp;
end;
procedure sorting(n:byte;var a:amhs);
var i,j,k
:byte;
begin
for
i:=1 to n do
begin
k:=i;
for
j:=i+1 to n do
if a[j].ipk>a[k].ipk then
k:=j;
swap2(a[i].nama,a[k].nama);
swap2(a[i].nim, a[k].nim);
swap (a[i].ipk, a[k].ipk);
end;
end;
begin
clrscr;
gotoxy(8,1);writeln('>> Program Sorting IPK <<');
writeln;
write ('Jumlah data :
');readln(jlh_mhs);
for a:=1
to jlh_mhs do
begin
writeln('Data ke-',a);
write (' Nama :
');readln(dtmhs[a].nama);
write (' NIM :
');readln(dtmhs[a].nim);
write (' IPK :
');readln(dtmhs[a].ipk);
end;
sorting(jlh_mhs,dtmhs);
clrscr;
gotoxy(16,1);writeln('>> Hasil Sorting <<');
writeln;
writeln('====================================================');
writeln('| No | Nama |
NIM |
IPK |');
writeln('|----|-------------------------|-----------|-------|');
for a:=1
to jlh_mhs do
begin
write('| | | | |');
gotoxy(3,wherey); write (a:2);
gotoxy(8,wherey); write
(dtmhs[a].nama);
gotoxy(34,wherey);write
(dtmhs[a].nim);
gotoxy(46,wherey);writeln(dtmhs[a].ipk:5:2);
end;
writeln('====================================================');
readkey;
end. |
kalauu untuk di C++ gmana kak?
BalasHapus