program tabelMHS;
uses crt;
type ket=record
nama:string;
nim:longint;
nilai:integer;
end;
var pil:char;
mhs:array[0..10] of ket;
min,max:integer;
label awal;
procedure input(data:integer);
var i:integer;
label daftar,atur;
begin
if data=1 then goto daftar;
for i:=0 to 10 do
begin
writeln('=================================');
writeln(' Input Data Mahasiswa ');
writeln('=================================');
write('[',i,']','Nama : ');readln(mhs[i].nama);
write('[',i,']','Nim : ');readln(mhs[i].nim);
atur:
write('[',i,']','Nilai: ');readln(mhs[i].nilai);
if (mhs[i].nilai < 0) or (mhs[i].nilai > 100) then
begin
writeln('Nilai min = 0 & max 100');
goto atur;
end;
if i=0 then
begin
min:=mhs[0].nilai;
max:=mhs[0].nilai;
end
else
begin
if mhs[i].nilai < min then min:= mhs[i].nilai;
if mhs[i].nilai > max then max:= mhs[i].nilai;
end;
clrscr;
end;
daftar:
clrscr;
writeln('=================================');
writeln(' Data Mahasiswa ');
writeln('=================================');
for i:=0 to 10 do
begin
write('[',i:2,']','Nama : ',mhs[i].nama:8);
write(' | ','NIM : ',mhs[i].nim:9);
write(' | ','Nilai : ',mhs[i].nilai:3);
writeln;
end;
writeln;
writeln('nilai terendah : ',min);
writeln('nilai tertinggi: ',max);
write('Tekan sembarang keyboard untuk kembali ke menu');
readln;
end;
procedure maxa;
var i,j:integer;
max:longint;
begin
j:=0;
max:=mhs[0].nim;
for i:=0 to 10 do
begin
if mhs[i].nim > max then
begin
max := mhs[i].nim;
j := i;
end;
end;
writeln('=================================');
writeln(' Nim Terbesar ');
writeln('=================================');
writeln('Nama : ',mhs[j].nama);
writeln('NIM : ',mhs[j].nim);
writeln('Nilai: ',mhs[j].nilai);
writeln;
write('Tekan sembarang keyboard untuk kembali ke menu');
readln;
end;
procedure bin;
var found:boolean;
x,i,awl,akh,tengah:integer;
label cari,temu;
begin
cari:
x:=0;found:=false;
awl:=0;akh:=10;
clrscr;
writeln('=================================');
writeln(' Pencarian Nilai ');
writeln('=================================');
write('Nilai yang dicari : ');readln(x);
writeln('=================================');
while (awl<=akh) and (not(found)) do
begin
tengah:=(awl+akh) div 2;
if x = mhs[tengah].nilai then
begin
i:=tengah;
found:=true;
goto temu;
end
else if x < mhs[tengah].nilai then
begin
awl:=tengah+1;
goto temu;
end
else if x > mhs[tengah].nilai then
begin
akh:=tengah-1;
goto temu;
end;
temu:
end;
if found then
begin
writeln('Nama : ',mhs[i].nama);
writeln('Nim : ',mhs[i].nim);
writeln('Nilai: ',mhs[i].nilai);
end
else
writeln('------ Data tidak ditemukan ------');
writeln;
write('Tekan sembarang keyboard untuk kembali ke menu');
readln;
end;
procedure urut(data:integer);
type tabint=record
hit:integer;
idx:array[0..10] of integer;
end;
var cek:array[0..100] of tabint;
tmpData:array[0..10] of ket;
i,j,k,id,idm:integer;
label urutin,tada;
begin
k:=0;
for i:=0 to 10 do
for j:=min to max do
begin
tmpData[i].nama := '';
tmpData[i].nim := 0;
tmpData[i].nilai := 0;
cek[j].hit:=0;
cek[j].idx[i]:=11;
end;
for i:=0 to 10 do
begin
idm:=0;
cek[mhs[i].nilai].hit := cek[mhs[i].nilai].hit + 1;
urutin:
if cek[mhs[i].nilai].idx[idm] <> 11 then
begin
idm:=idm+1;
goto urutin;
end
else cek[mhs[i].nilai].idx[idm]:=i;
end;
k:=0;
for i:=max downto min do
begin
if cek[i].hit > 0 then
begin
for j:=1 to cek[i].hit do
begin
id:=cek[i].idx[j-1];
tmpData[k] := mhs[id];
k:=k+1;
end;
end;
end;
mhs:=tmpData;
if data=0 then begin bin; goto tada; end;
writeln('=================================');
writeln(' 3 Nilai Terbesar ');
writeln('=================================');
for i:=0 to 2 do
begin
writeln;
writeln(i+1,'. Nama : ',mhs[i].nama);
writeln(' Nim : ',mhs[i].nim);
writeln(' Nilai: ',mhs[i].nilai);
end;
writeln;
write('Tekan sembarang keyboard untuk kembali ke menu');
readln;
tada:
end;
begin
awal :
clrscr;
writeln('=================================');
writeln(' Menu Utama ');
writeln('=================================');
writeln('1. Input Data Mahasiswa ');
writeln('2. Nim terbesar');
writeln('3. Cari Nilai');
writeln('4. Urutan Data Mahasiswa');
writeln('5. Lihat Data Mahasiswa');
writeln('6. Exit');
writeln('=================================');
write('Pilih : ');readln(pil);
Case pil of
'1': begin
clrscr;
input(0);
goto awal;
end;
'2': begin
clrscr;
maxa;
goto awal;
end;
'3': begin
clrscr;
urut(0);
goto awal;
end;
'4': begin
clrscr;
urut(1);
goto awal;
end;
'5': begin
clrscr;
input(1);
goto awal;
end;
'6': EXIT;
else
begin
writeln('----------------------------------------');
writeln('Tekan sembarang keyboard untuk mengulang');
readln;
goto awal;
end;
end;
end.
Algoritma dan Pemerograman : Nilai Mahasiswa
Info Post
0 comments:
Post a Comment
Ayo diskusi disini ..