Contoh Pascal Record
Nah, setelah tau definisi Record Pascal, sekarang saya akan memberi contoh penggunaannya dalam bentuk record mahasiswa.
Yang dimana, mahasiswa angkatan 2010 keatas adalah SENIOR, sedangkan mahasiswa 2010 dan seterusnya adalah JUNIOR. Contoh : 2011, 2012, 2013, 2014 (JUNIOR).
=============================================
Program RecordMahasiswa;
uses wincrt;
type mahasiswa = RECORD
NPM : String;
Nama : String;
Thnmasuk: Integer;
ket : String;
end;
var
mhs : Array[1..50] of mahasiswa;
x,y,z:Integer;
begin
clrscr;
writeln('------------------------------------------------');
writeln(' PROGRAM RECORD ');
writeln('------------------------------------------------');
write (' Banyak data mahasiswa yang akan dimasukkan: ');
readln (x);
writeln (' ') ;
for y:=1 to x do
begin
with mhs[y] do
begin
write(' NPM mahasiswa : ');
readln(NPM);
write(' Nama mahasiswa : ');
readln(Nama);
write(' Tahun masuk : ');
readln(Thnmasuk);
writeln(' ');
end;
end;
clrscr;
writeln(' ');
writeln(' DAFTAR NAMA MAHASISWA ');
writeln('----------------------------------------------------------------------');
writeln('| NO | NPM | NAMA | TAHUN MASUK | KET |');
writeln('----------------------------------------------------------------------');
for y:=1 to x do
begin
gotoxy(1,y+5);write('|');
gotoxy(3,y+5);write(y);
with mhs[y] do
begin
gotoxy(6,y+5);write('|');
gotoxy(8,y+5);
write(NPM);
gotoxy(19,y+5);write('|');
gotoxy(21,y+5);
write(Nama);
gotoxy(45,y+5);write('|');
gotoxy(51,y+5);
write(Thnmasuk);
gotoxy(60,y+5);write('|');
z := 2014 - Thnmasuk;
if z>3 then ket := 'Senior' else
ket:='Junior';
gotoxy(63,y+5);
write(ket);
gotoxy(70,y+5);write('|');
end;
end;
writeln(' ');
writeln('----------------------------------------------------------------------');
readln;
end.
=====================================================
Berikut hasil outputnya :
Yang dimana, mahasiswa angkatan 2010 keatas adalah SENIOR, sedangkan mahasiswa 2010 dan seterusnya adalah JUNIOR. Contoh : 2011, 2012, 2013, 2014 (JUNIOR).
=============================================
Program RecordMahasiswa;
uses wincrt;
type mahasiswa = RECORD
NPM : String;
Nama : String;
Thnmasuk: Integer;
ket : String;
end;
var
mhs : Array[1..50] of mahasiswa;
x,y,z:Integer;
begin
clrscr;
writeln('------------------------------------------------');
writeln(' PROGRAM RECORD ');
writeln('------------------------------------------------');
write (' Banyak data mahasiswa yang akan dimasukkan: ');
readln (x);
writeln (' ') ;
for y:=1 to x do
begin
with mhs[y] do
begin
write(' NPM mahasiswa : ');
readln(NPM);
write(' Nama mahasiswa : ');
readln(Nama);
write(' Tahun masuk : ');
readln(Thnmasuk);
writeln(' ');
end;
end;
clrscr;
writeln(' ');
writeln(' DAFTAR NAMA MAHASISWA ');
writeln('----------------------------------------------------------------------');
writeln('| NO | NPM | NAMA | TAHUN MASUK | KET |');
writeln('----------------------------------------------------------------------');
for y:=1 to x do
begin
gotoxy(1,y+5);write('|');
gotoxy(3,y+5);write(y);
with mhs[y] do
begin
gotoxy(6,y+5);write('|');
gotoxy(8,y+5);
write(NPM);
gotoxy(19,y+5);write('|');
gotoxy(21,y+5);
write(Nama);
gotoxy(45,y+5);write('|');
gotoxy(51,y+5);
write(Thnmasuk);
gotoxy(60,y+5);write('|');
z := 2014 - Thnmasuk;
if z>3 then ket := 'Senior' else
ket:='Junior';
gotoxy(63,y+5);
write(ket);
gotoxy(70,y+5);write('|');
end;
end;
writeln(' ');
writeln('----------------------------------------------------------------------');
readln;
end.
=====================================================
Berikut hasil outputnya :


Komentar
Posting Komentar