Rabu, 18 Mei 2011

membuat program pascal menggunakan array dalam record

uses wincrt;

type tb_mhs=record
nim:longint;
nama:string;
nilai:integer;
end;

var
mhs:array[1..10] of tb_mhs;
a,b,ke:integer;
tukar:tb_mhs;
pilih:char;
posisi:array[1..10] of integer;

begin
pilih:='y';
while ((pilih='y') or (pilih='Y')) do
begin
ke:=ke+1;
writeln;
writeln('masukkan data mahasiswa ke ',ke,' :');
writeln('===================================');
write('masukkan nim : ');readln (mhs[ke].nim);
write('masukkan nama : ');readln (mhs[ke].nama);
write('masukkan nilai: ');readln(mhs[ke].nilai);
writeln('====================================');
write('ingin tambah mahasiswa ? y/t: ');readln(pilih);
end;

for a:=1 to ke do
begin
for b:=a+1 to ke do
begin

if mhs[a].nilai tukar:=mhs[a];
mhs[a]:=mhs[b];
mhs[b]:=tukar;

end;

clrscr;
for a:=1 to ke do
begin
writeln;
writeln(' tabel mahasiswa ');
writeln('--------------------------');
writeln('no | nim | nama | nilai |');
writeln('==========================');
for a:=1 to ke do
writeln(a:4,'|',mhs[a].nim:7,'|',mhs[a].nama:8,'|',mhs[a].nilai:8,'|');
writeln('--------------------------');
writeln;

end;
end;
end.

Tidak ada komentar:

Poskan Komentar