·
Program pascal menggunakan Procedure
dan Function
Ø Pascal
menggunakan Procedure
-Listing
Program:
uses crt ;
var pil : integer ;
Procedure lingkaran ;
var x,y,z : real ;
begin
writeln ( ` --- 1.lingkaran--- ` ) ;
write ( `masukan jari-jari: ` ) ;
readln (x) ;
y := 3.14 * x * x ;
z := 2 * x * 3.14 ;
writeln ( `luas lingkaran = ` , y : 9 : 2 ) ;
writeln ( `keliling lingkaran = ` ,
z : 9 : 2 ) ;
end ;
Procedure persegi ;
var x,y,z : real ;
begin
writeln ( ` ---2.persegi--- ` ) ;
write ( `masukan sisi: ` ) ;
readln (x) ;
y := x * x ;
z := x * 4 ;
writeln ( `luas persegi = ` , y : 9 : 2 ) ;
writeln ( `keliling persegi = ` , z
: 9 : 2 ) ;
end ;
Procedure persegi_panjang ;
var p,l,y,z : real ;
begin
writeln ( ` ---3.persegi_panjang---
` ) ;
write ( `masukan panjang: ` ) ;
readln (p) ;
write ( `masukan lebar: ` ) ;
readln (l) ;
y := p * l ;
z := 2 * ( p + l ) ;
writeln ( ` luas persegi
panjang =' , y : 9 : 2 ) ;
writeln ( `keliling persegi panjang
=' , z : 9 : 2 ) ;
end ;
begin
clrscr ;
writeln ( `program luas dan
keliling' ) ;
writeln () ;
writeln ( '1 = lingkaran' ) ;
writeln ( '2 = persegi' ) ;
writeln ( '3 = persegi panjang' ) ;
writeln () ;
write ( `masukan pilihan :' ) ;
readln (pil) ;
writeln () ;
if pil = 1 then lingkaran
else if pil = 2 then persegi
else if pil = 3 then persegi_panjang
else write ( `input salah' ) ;
readln
end.
-0utput
Program
Ø Pascal
menggunakan Function
-
Listing Program:
program tunjangan;
uses wincrt;
var
nm,jab,no :string;
gaj,ti,ta,tgaj:real;
stat,jmlank :integer;
function gajibersih
(gaji,tunjangan_anak,tunjangan_istri,totalgaji :real):real;
begin
gajibersih:=gaji+tunjangan_anak+tunjangan_istri;
end;
begin
writeln('=================================================');
writeln('=TUGAS PERHITUNGAN GAJI DAN TUNJANGAN ANAK ISTRI=');
writeln('=Nama :Muhammad Asrir
NIM :2010020112 =');
writeln('=================================================');
writeln('= Masukkan data sesuai
pada ketentuan berikut =');
writeln('=================================================');
writeln('======Status=====================================');
writeln(' 1. Kawin ');
writeln(' 2. Tidak Kawin ');
writeln('=================================================');
writeln;
writeln;
write ('nomor induk karyawan : ');readln(no);
write ('nama pegawai : ');readln(nm);
write ('jabatan pegawai : ');readln(jab);
write ('Gaji pokok : Rp,');readln(gaj);
write ('status perkawinan : ');readln(stat);
case stat of
1 :begin
ti :=(15/100)*gaj;
write ('jumlah anak : ');readln(jmlank);
if (jmlank >=3) then
ta :=(5/100)*gaj
else if (jmlank <3) then
ta :=0;
end;
2 :begin
ti :=0;
ta :=0;
end;
end;
begin
writeln;
writeln('=================oO SLIP GAJI Oo=================');
writeln;
writeln ('Nama : ',nm);
writeln ('No Karyawan : ',no);
writeln ('Jabatan : ',jab);
writeln ('+===============================================+');
writeln ('| Rincian
Gaji | Jumlah |');
writeln ('+===============================================+');
writeln ('| Gaji Pokok
: | Rp ',gaj:8:0,' |');
writeln ('| Tunjangan Anak
: | Rp ',ta:8:0,' |');
writeln ('| Tunjangan Istri
: | Rp ',ti:8:0,' |');
writeln ('|
| |');
writeln ('+===============================================+');
writeln ('| Total Gaji Bersih
: | Rp ',gajibersih (gaj,ti,ta,tgaj):8:0,' |');
writeln ('+===============================================+');
readln;
end;
end.
-output
Program
Output program kurang lebih begini saat berjalan.
tq atas program di atas....
BalasHapus