Salah satu penggunaan record pada bahasa pemrograman pascal adalah array of record atau mengakses record dengan array. Biasanya array of record dipakai untuk membuat program sepertidata mahasiswa, struk penjualan, dan program yang berhubungan dengan perekapan data lainnya. Berikut contoh program data mahasiswa menggunakan array of record yang saya buat :
uses crt;
type mhs = record
nama:string;
nim:string;
nilai:byte;
grade:shortstring;
end;
var data: array [1..100] of mhs;
pilih: char;
var i,n :byte;
procedure input;
begin
clrscr;
gotoxy(15,1);writeln('Data Mahasiswa');
gotoxy(15,2);writeln('--------------'); writeln;
write('Masukan Jumlah Mahasiswa : '); readln(n);
clrscr;
for i:= 1 to n do
begin
with data[i] do
begin
writeln('Data ke-',i);
writeln('-------------------------');
write('Nama : '); readln(nama);
write('NIM : '); readln(nim);
write('Nilai : '); readln(nilai);
writeln;
end
end;
end;
procedure tabel;
begin
writeln('_____________________________________________________________');
writeln('| No. | NIM | Nama | Nilai | Grade |');
writeln('-------------------------------------------------------------');
for i:=1 to n do
begin
gotoxy(1,i+3);
writeln('| | | | | |');
end; writeln('-------------------------------------------------------------');
end;
procedure output;
begin
clrscr;
tabel;
for i:= 1 to n do
begin
with data[i] do
begin
if (nilai>=80) and (not(nilai>100)) then grade:='A' else
if (nilai>=75) and (not(nilai>79)) then grade:='B+' else
if (nilai>=65) and (not(nilai>74)) then grade:='B' else
if (nilai>=60) and (not(nilai>64)) then grade:='C+' else
if (nilai>=55) and (not(nilai>59)) then grade:='C' else
if (nilai>=45) and (not(nilai>54)) then grade:='D+' else
if (nilai>=35) and (not(nilai>44)) then grade:='D' else
grade:='E'; end; end;
for i:= 1 to n do
begin
with data[i] do
begin
gotoxy(3,i+3); writeln(i);
gotoxy(9,i+3); writeln(nim);
gotoxy(21,i+3); writeln(nama);
gotoxy(45,i+3); writeln(nilai);
gotoxy(55,i+3); writeln(grade);
end;
end;
readln;
end;
begin
repeat
clrscr;
gotoxy(20,1);writeln('Data Mahasiswa');
gotoxy(20,2);writeln('--------------');
writeln;
writeln('[1] Rekap Data');
writeln('[2] Hasil Rekap');
writeln('[3] Keluar'); writeln;
write('Pilih : ');
pilih:= readkey;
case pilih of
'1' : input;
'2' : output;
'3' : exit;
end;
until pilih = '3'
end.
Hasil setelah program dijalankan :
0 Comment to "Array of Record Data Mahasiswa"
Post a Comment