Berikut adalah Source Code Program Mengurutkan Data Siswa Berdasarkan Nilai dalam Bahasa Pascal.

Data arsip dari Die Coding, silakan digunakan dan diubah sesuka hati, semoga bermanfaat.

program pengurutanDataSiswa;
uses crt;

var
	nama, nis: array[1..500] of string;
	C, D, E, total, rerata: array[0..500] of real;
	i, j, n: integer;
	mat, bin, ipa, jml, rata: real;
	nm, ns: string;
	p: byte;
	q: string[1];

{ ===== JEDA SESAAT ===== }
procedure pause;
begin
	writeln;writeln;writeln;
	write('Tekan sembarang tombol untuk melanjutkan...');
	readkey;
end;
	
procedure TabelNis;
begin
    if length(nis[i])= 7 then write('| ',nis[i],' | ') else
	if length(nis[i])= 6 then write('| ',nis[i],'  | ') else
	if length(nis[i])= 5 then write('| ',nis[i],'   | ') else
	if length(nis[i])= 4 then write('| ',nis[i],'    | ') else
	if length(nis[i])= 3 then write('| ',nis[i],'     | ') else
	if length(nis[i])= 2 then write('| ',nis[i],'      | ') else
	if length(nis[i])= 1 then write('| ',nis[i],'       | ');
end;

procedure TabelNama;
begin
	case length(nama[i]) of
		1 : write(nama[i],'                          | ');
		2 : write(nama[i],'                         | ');
		3 : write(nama[i],'                        | ');
		4 : write(nama[i],'                       | ');
		5 : write(nama[i],'                      | ');
		6 : write(nama[i],'                     | ');
		7 : write(nama[i],'                    | ');
		8 : write(nama[i],'                   | ');
		9 : write(nama[i],'                  | ');
		10: write(nama[i],'                 | ');
		11: write(nama[i],'                | ');
		12: write(nama[i],'               | ');
		13: write(nama[i],'              | ');
		14: write(nama[i],'             | ');
		15: write(nama[i],'            | ');
		16: write(nama[i],'           | ');
		17: write(nama[i],'          | ');
		18: write(nama[i],'         | ');
		19: write(nama[i],'        | ');
		20: write(nama[i],'       | ');
		21: write(nama[i],'      | ');
		22: write(nama[i],'     | ');
		23: write(nama[i],'    | ');
		24: write(nama[i],'   | ');
		25: write(nama[i],'  | ');
		26: write(nama[i],' | ');
	end;
end;

procedure TabelMtk;
begin
	if C[i] = 100 then write(C[i]:3:0,'   | ') else
	if C[i] < 100 then begin
		if C[i] >= 10 then write(C[i]:2:1,'  | ') else
		write(C[i]:1:2,'  | ');
	end;
end;

procedure TabelBin;
begin
	if D[i] = 100 then write(D[i]:3:0,'   | ') else
	if D[i] < 100 then begin
		if D[i] >= 10 then write(D[i]:2:1,'  | ') else
		write(D[i]:1:2,'  | ');
	end;
end;

procedure TabelIpa;
begin
	if E[i] = 100 then write(E[i]:3:0,'   | ') else
	if E[i] < 100 then begin
		if E[i] >= 10 then write(E[i]:2:1,'  | ') else
		write(E[i]:1:2,'  | ');
	end;
end;

procedure TabelTotal;
begin
	if total[i] >= 100 then write(total[i]:3:0,'   |  ') else
	if total[i] < 100 then begin
		if total[i] >= 10 then write(total[i]:2:1,'  |  ') else
		write(total[i]:1:2,'  |  ');
	end;
end;

procedure TabelRerata;
begin
	if rerata[i] = 100 then write(rerata[i]:3:0,'      |') else
	if rerata[i] < 100 then begin
		if rerata[i] >= 10 then write(rerata[i]:2:1,'     |') else
		write(rerata[i]:1:2,'     |');
	end;
end;

procedure DataUrut;
begin
	ns := nis[i];
	nis[i] := nis[j];
	nis[j] := ns;
	
	nm := nama[i];
	nama[i] := nama[j];
	nama[j] := nm;
	
	mat := C[i];
	C[i] := C[j];
	C[j] := mat;
	
	bin := D[i];
	D[i] := D[j];
	D[j] := bin;
	
	ipa := E[i];
	E[i] := E[j];
	E[j] := ipa;
	
	jml := total[i];
	total[i] := total[j];
	total[j] := jml;
	
	rata := rerata[i];
	rerata[i] := rerata[j];
	rerata[j] := rata;
end;

procedure Pilihan;
begin
	writeln;
	writeln('Silahkan pilih metode mengurutkan nilai siswa yang anda inginkan');
	writeln(' 1 - Urutkan siswa berdasarkan total nilai');
	writeln(' 2 - Urutkan siswa berdasarkan nilai Matematika');
	writeln(' 3 - Urutkan siswa berdasarkan nilai Bahasa Indonesia');
	writeln(' 4 - Urutkan siswa berdasarkan nilai IPA');
	writeln;
	write('Silahkan masukan pilihan anda : ');readln(p); 
	
	{ ===== PILIHAN 1 ===== } 
	if p = 1 then
	begin
		for i := 1 to n-1 do
		for j := i to n do
		if total[i] < total[j] then
		DataUrut;
	end;
	
	{ ===== PILIHAN 2 ===== }
	if p = 2 then
	begin
		for i := 1 to n-1 do
		for j := i to n do
		if C[i] < C[j] then
		DataUrut;
	end;
	
	{ ===== PILIHAN 3 ===== }
	if p = 3 then
	begin
		for i := 1 to n-1 do
		for j := i to n do
		if D[i] < D[j] then
		DataUrut;
	end;
	
	{ ===== PILIHAN 4 ===== }
	if p = 4 then
	begin
		for i := 1 to n-1 do
		for j := i to n do
		if E[i] < E[j] then
		DataUrut;
	end;
	
	{ ===== PILIHAN LAIN ===== }
	if (p > 4) or (p < 1) then
	begin
		writeln('Pilihan salah !');
		writeln;
		write('Ulangi masukan pilihan   : ');readln(p);
	end;
end;

procedure Isi;
begin
	repeat
	begin
		writeln('           Selamat datang di program Mengurutkan Siswa Berdasarkan Nilai            ');
		writeln('                           Masukan jumlah siswa :  [500]                            ');
		write('                                        ');readln(n);
		if (n > 500) or (n <= 0) then
		begin
			writeln('Nilai tidak valid !');
			writeln;
			writeln('                       Ulangi Masukan jumlah siswa :  [500]                         ');
			write('                                        ');readln(n);
		end;
		clrscr;

		{ ===== DATA SISWA ===== }
		for i := 1 to n do
		begin
			writeln('Siswa ke - ',i);
			write('Nama                    : ');readln(nama[i]);
			if length(nama[i]) > 26 then
			begin
				writeln('Karakter melebihi batas maksimal [26] !');
				writeln;
				write('Ulangi masukan Nama     : ');readln(nama[i]);
			end;
			write('Nomor Induk Siswa (NIS) : ');readln(nis[i]);
			if length(nis[i]) > 7 then
			begin
				writeln('Karakter melebihi batas maksimal [7] !');
				writeln;
				write('Ulangi masukan NIS      : ');readln(nis[i]);
			end;
			write('Nilai Matematika        : ');readln(C[i]);
			if (C[i] > 100) or (C[i] < 0) then
			begin
				writeln('Nilai tidak valid !');
				writeln;
				write('Ulangi masukan Nilai    : ');readln(C[i]);
			end;
			write('Nilai Bahasa Indonesia  : ');readln(D[i]);
			if (D[i] > 100) or (D[i] < 0) then
			begin
				writeln('Nilai tidak valid !');
				writeln;
				write('Ulangi masukan Nilai    : ');readln(D[i]);
			end;
			write('Nilai IPA               : ');readln(E[i]);
			if (E[i] > 100) or (E[i] < 0) then
			begin
				writeln('Nilai tidak valid !');
				writeln;
				write('Ulangi masukan Nilai    : ');readln(E[i]);
			end;
			writeln;
			total[i] := C[i]+D[i]+E[i]; // Total
			rerata[i] := total[i]/3;    // Rata-Rata
		end;
		
		writeln;writeln;
		writeln('Data sejumlah ',n,' berhasil dimasukan !');
		Pilihan; // Pilihan Pengurutan
		writeln;writeln;
		writeln(' ---------------------------------------------------------------------------------- ');
		writeln('|                                  DATA NILAI SISWA                                |');
		
		{ Kolom NIS: 1-7, Nama: 1-26, Nilai: 4, Total: 4, Rata-Rata: 4 }
		writeln(' ================================================================================== ');
		writeln('|         |                            |         Nilai         |       |           |');
		writeln('|   NIS   |         Nama Siswa         |-----------------------| Total | Rata-Rata |');
		writeln('|         |                            |  Mat  | B.Ind |  IPA  |       |           |');
		writeln('|---------|----------------------------|-------|-------|-------|-------|-----------|');
		
		for i := 1 to n do
		begin
			TabelNis;
			TabelNama;
			TabelMtk;
			TabelBin;
			TabelIpa;
			TabelTotal;
			TabelRerata;
			writeln;
		end;
		writeln(' ---------------------------------------------------------------------------------- ');
		writeln;
		
		write('Ingin mengulanginya? <y/t> ');readln(q);
		clrscr;
	end;
	until(q <> 'y');
end;

{ ===== PROGRAM UTAMA ===== }
begin
	clrscr;  
	writeln('====================================================================================');
	writeln(' =                                                                                = ');
	writeln(' =                             source: diecoding.com                              = ');
	writeln(' =                                                                                = ');
	writeln('====================================================================================');
	pause;
	clrscr;
	Isi;
	writeln('Terima kasih telah menggunakan program kami');
	readkey;
end.