Program : sorting data mahasiswa
pemrograman : pascal
IDE : turbo pascal 7.0
Berikut data mahasiswa sebelum di sorting :
Data mahasiswa setelah sorting berdasarkan Npm :
Data mahasiswa setelah sorting berdasarkan nama :
Data mahasiswa setelah sorting berdasarkan kelas :
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.
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.
1 komentar:
hei kawan, yuk kita ikut lomba 10 kategori lomba khusus bagi mahasiswa Universitas Gunadarma. Edisi
Desember2012 ini diperuntukan bagi mahasiswa S1 dan D3. Tersedia 100 pemenang, atau 10 pemenang
untuk setiap kategori. link
http://studentsite.gunadarma.ac.id/news/news.php?stateid=shownews&idn=755
makasi :)
Posting Komentar