Program

Program queue_contoh;

Uses crt;

Const max = 10;

Type

antri = record

uts: array [1..max] of real;

uas: array [1..max] of real;

harian: array [1..max] of real;

rerata: array [1..max] of real;

posisi : 1..max;



end;



Var

i,w : integer;



Function kosong (q:antri) :boolean;

Begin

Kosong:=(q.posisi=0);

End;



Function penuh(q:antri) :boolean;

Begin

Penuh :=(q.posisi=max);

End;



Procedure tambah(var antrian:antri; x:real;y:real;z:real);

Begin

{menambah elemen baru}

if not penuh(antrian) then

begin

antrian.posisi :=antrian.posisi + 1;

antrian.uts[antrian.posisi] :=x;

antrian.uas[antrian.posisi] :=y;

antrian.harian[antrian.posisi] :=z;

antrian.rerata[antrian.posisi]:=(x+y+z)/3;

w:=antrian.posisi;

end

else

writeln('Antrian sudah penuh');

End;



Procedure Keluar(var antrian:antri);

begin

if kosong(antrian) then

write('Antrian Kosong')

else

begin

for i := 1 to antrian.posisi-1 do

begin

antrian.rerata[i]:= antrian.rerata[i+1];

antrian.posisi := antrian.posisi - 1;

w:=antrian.posisi;

end;

write('Data telah berhasil keluar dari antrian');

end;

readln;

end;



procedure tampil(antrian : antri);

begin

for i := 1 to antrian.posisi do

begin

write('Data ke-',i,' UAS : ',antrian.uas[i]:3:2);

write(' UTS : ',antrian.uts[i]:3:2);

write(' Harian : ',antrian.harian[i]:3:2);

writeln(' Rata-rata : ',antrian.rerata[i]:3:2);

end;

readln;

end;



procedure tampilurut(antrian : antri);

var

j,lokasi:integer;

Bantu,bantu2,bantu3,bantu4:real;

begin

for i := 1 to w do

begin

Lokasi := i;

For j:= i+1 to w do

If antrian.rerata[lokasi]
begin

Lokasi:=j;

Bantu:=antrian.rerata[i];

Bantu2:=antrian.uas[i];

Bantu3:=antrian.uts[i];

Bantu4:=antrian.harian[i];



antrian.rerata[i]:=antrian.rerata[lokasi];

antrian.uas[i]:=antrian.uas[lokasi];

antrian.uts[i]:=antrian.uts[lokasi];

antrian.harian[i]:=antrian.harian[lokasi];



antrian.rerata[lokasi]:=bantu;

antrian.uas[lokasi]:=bantu2;

antrian.uts[lokasi]:=bantu3;

antrian.harian[lokasi]:=bantu4;

end;

end;



for i := 1 to antrian.posisi do

begin

write('Data ke-',i,' UAS : ',antrian.uas[i]:3:2);

write(' UTS : ',antrian.uts[i]:3:2);

write(' Harian : ',antrian.harian[i]:3:2);

writeln(' Rata-rata : ',antrian.rerata[i]:3:2);

end;

readln;

end;



procedure tampilurutasc(antrian : antri);

var

j,lokasi:integer;

Bantu,bantu2,bantu3,bantu4:real;

begin

for i := 1 to w do

begin

Lokasi := i;

For j:= i+1 to w do

If antrian.rerata[lokasi]>antrian.rerata[j] then

begin

Lokasi:=j;

Bantu:=antrian.rerata[i];

Bantu2:=antrian.uas[i];

Bantu3:=antrian.uts[i];

Bantu4:=antrian.harian[i];



antrian.rerata[i]:=antrian.rerata[lokasi];

antrian.uas[i]:=antrian.uas[lokasi];

antrian.uts[i]:=antrian.uts[lokasi];

antrian.harian[i]:=antrian.harian[lokasi];



antrian.rerata[lokasi]:=bantu;

antrian.uas[lokasi]:=bantu2;

antrian.uts[lokasi]:=bantu3;

antrian.harian[lokasi]:=bantu4;

end;

end;



for i := 1 to antrian.posisi do

begin

write('Data ke-',i,' UAS : ',antrian.uas[i]:3:2);

write(' UTS : ',antrian.uts[i]:3:2);

write(' Harian : ',antrian.harian[i]:3:2);

writeln(' Rata-rata : ',antrian.rerata[i]:3:2);

end;

readln;

end;



procedure menu(var pilihan:byte);

begin

clrscr;

writeln('1. Menambah data Untuk Diurutkan');

writeln('2. Mengeluarkan/menghapus data');

writeln('3. Menampilkan data sebelum diurutkan');

writeln('4. Menampilkan data urut rata2 descanding');

writeln('5. Menampilkan data urut rata2 ascanding');

writeln('6. Keluar');

write('Pilihan : ');

readln(pilihan);

end;



var

a : antri;

pilihan : byte;

elemen,elemen2,elemen3: real;

begin

repeat

menu(pilihan);

case pilihan of

1:

begin

write('Masukan Nilai UAS : ');

readln(elemen);

write('Masukan Nilai UTS : ');

readln(elemen2);

write('Masukan Nilai Harian : ');

readln(elemen3);

tambah(a,elemen,elemen2,elemen3);

end;

2:

begin

keluar(a);

end;

3:

begin

tampil(a);

end;

4:

begin

tampilurut(a);

end;

5:

begin

tampilurutasc(a);

end;

end;

until pilihan = 6;

end.

0 komentar:

Posting Komentar

Silakan Tinggalken Pesan