Sekarang saya akan membagikan tugas akhir dari mata kuliah Algoritma Pemrograman saat saya masih semester 2. Program ini menggunakan bahasa Pascal yang berisi sebuah Menu untuk membantu pengguna mencari suatu nilai statistik dari rata-rata, modus, median, standart deviasi, dll. Nah, langsung saja kita lihat dan coba syntax di bawah ini....
program oi;
uses crt;
type data=array[1..100] of integer;
var
i,n,j:integer;
a:data;
procedure menu;
begin
clrscr;
gotoxy(20,5); writeln('|------------------------|');
gotoxy(20,6); writeln('| MENU |');
gotoxy(20,7); writeln('|========================|');
gotoxy(20,8); writeln('| |');
gotoxy(20,9); writeln('| 1. Mean |');
gotoxy(20,10); writeln('| 2. Modus |');
gotoxy(20,11); writeln('| 3. Median |');
gotoxy(20,12); writeln('| 4. Variance |');
gotoxy(20,13); writeln('| 5. Standart Deviasi |');
gotoxy(20,14); writeln('| 6. Pengurutan |');
gotoxy(20,15); writeln('| 7. Input data |');
gotoxy(20,16); writeln('| 8. exit |');
gotoxy(20,17); writeln('| |');
gotoxy(20,18); writeln('|========================|');
end;
procedure menu2;
var k:byte;
begin
writeln;
writeln('----------------');
writeln(' 9. Menu');
readln(k);
if k<>9 then
begin
repeat
writeln('Ulangi');
readln(k);
until k=9;
menu;
end
else
menu;
end;
procedure tampil;
begin
write('Menampilkan Data: ');
for i:=1 to n do
begin
write(a[i],' ');
end;
writeln;
writeln;
end;
procedure input;
begin
writeln(' INPUT DATA ');
writeln('==================');
write('Masukkan Banyak Data: '); readln(n);
writeln;
for i:=1 to n do
begin
write(' Data ke-',i,' : '); readln(a[i]);
end;
end;
procedure urut1;
var z:integer;
begin
for i:=1 to n-1 do
begin
for j:=n downto i+1 do
begin
if a[j] < a[j-1] then
begin
z:=a[j];
a[j]:=a[j-1];
a[j-1]:=z;
end;
end;
end;
end;
procedure urut2;
var z:integer;
begin
for i:=1 to n-1 do
begin
for j:=n downto i+1 do
begin
if a[j] > a[j-1] then
begin
z:=a[j];
a[j]:=a[j-1];
a[j-1]:=z;
end;
end;
end;
end;
procedure menuurut;
var pil:byte;
begin
write('Masukkan Pilihan: '); readln(pil);
case pil of
1: begin
clrscr;
tampil;
urut1;
for j:=1 to n do
begin
write(a[j],' ');
end;
menu2;
end;
2: begin
clrscr;
tampil;
urut2;
for j:=1 to n do
begin
write(a[j],' ');
end;
menu2
end;
end;
end;
function median:real;
var letak:integer;
begin
letak:=(n+1) div 2;
begin
if n mod 2=0 then
median:=(a[letak]+a[letak+1]) div 2
else
median:=a[letak];
end;
end;
function mean:real;
var jum:integer;
begin
jum:=0;
for i:=1 to n do
begin
jum:=jum+a[i];
end;
mean:=jum/n;
end;
function varian:real;
var jum,rata:real;
begin
jum:=0;
rata:=mean;
for i:=1 to n do
begin
jum:=jum+sqr(a[i]-rata);
end;
varian:=jum/(n-1);
end;
function std:real;
var variance:real;
begin
variance:=varian;
std:=sqrt(variance);
end;
function modus:integer;
type dus=array[1..100] of integer;
var mo:dus;
begin
for i:=1 to n do
begin
mo[i]:=0;
for j:=i+1 to n do
begin
if a[i]=a[j] then
mo[i]:=mo[i]+1;
end;
end;
for i:=1 to n do
begin
if mo[i]>0 then
modus:=i;
end;
end;
var
batas:integer;
pilih:byte;
begin
clrscr;
input;
menu;
repeat
gotoxy(22,20); write(' Masukkan Pilihan: '); readln(pilih);
case pilih of
1: begin
clrscr;
tampil;
writeln('****************');
writeln('| MEAN |');
writeln('================');
writeln(' ',mean:0:2);
menu2;
end;
2: begin
clrscr;
tampil;
writeln('******************');
writeln('| MODUS |');
writeln('==================');
writeln(' ',a[modus]);
menu2;
end;
3: begin
clrscr;
tampil;
urut1;
writeln('*******************');
writeln('| MEDIAN |');
writeln('===================');
writeln(' ',median:0:1);
menu2;
end;
4: begin
clrscr;
tampil;
writeln('*****************');
writeln('| VARIANCE |');
writeln('=================');
writeln(' ',varian:0:2);
menu2;
end;
5: begin
clrscr;
tampil;
writeln('********************');
writeln('| Standart Deviasi |');
writeln('====================');
writeln(' ',std:0:2);
menu2;
end;
6: begin
clrscr;
tampil;
writeln(':=================:');
writeln('| Pengurutan |');
writeln('|=================|');
writeln('| 1. Ascending |');
writeln('| 2. Descending |');
writeln('|=================|');
writeln;
menuurut;
end;
7: begin
clrscr;
input;
writeln;
menu;
end;
8: exit;
end;
until batas=8;
end.
Silahkan teman-teman coba sendiri program di atas, semoga bermanfaat.
jangan lupa coment untuk saran dan pesan :D
Terima Kasih...
jangan lupa coment untuk saran dan pesan :D
Terima Kasih...
Tidak ada komentar:
Posting Komentar