Minggu, 15 September 2013

Contoh Pemograman Pascal

Program Menghitung Jumlah Bilangan Perulangan FOR Dengan Nilai Statis
Skrip Program Pascal
Output Program
program jum_bil; 
uses wincrt;
var
i, jum,bil: integer;
begin
jum:=0; {inisialisasi}
for i:=1 to 5 do
begin
write(‘Masukkan Bilangan = ‘);readln(bil);
jum:=jum+bil;
end;
writeln(‘Jumlah Bilangan = ‘,jum);
end.
Masukkan Bilangan = 12 
Masukkan Bilangan = 12
Masukkan Bilangan = 12
Masukkan Bilangan = 12
Masukkan Bilangan = 12
Jumlah Bilangan = 60
Program Menghitung Jumlah Bilangan Perulangan FOR Dengan Nilai Dinamis
Skrip Program Pascal
Output Program
program jum_bil2; 
uses wincrt;
var
i, n: integer;
jum, bil: real;
begin
write(‘Banyak bilangan :  ’);read(n);
jum := 0;
For i:= 1 to n do
begin
write(‘Masukkan Bilangan ‘,i, ‘=’);read(bil);
jum := jum+bil;
end;
writeln(‘Jum = ‘,jum:0:2);
end.
Banyak bilangan : 3 
Masukkan Bilangan 1 = 12
Masukkan Bilangan 2 = 13
Masukkan Bilangan 3 = 14
Jum = 39.00
Program Menghitung Jumlah dan Mean Bilangan Perulangan FOR Dengan Nilai Dinamis
Skrip Program Pascal
Output Program
program contoh_3; 
uses wincrt;
var
n, i : integer;
rata : real;
jum, bil : integer;
begin 
Write(‘Masukkan nilai N = ‘);readln(n);
writeln (‘Nilai N adalah= ‘,n);writeln;
for i := 1 to n do
begin
write(‘Masukkan bilangan : ‘);read(bil);
jum := jum+bil;
end;
rata := jum/n;writeln;
writeln(‘Jumlahnya adalah : ‘,jum);
writeln(‘Nilai rata-ratanya :’, rata:0:2);
end.
Masukkan nilai N = 3 
Nilai N adalah= 3
Masukkan bilangan: 1
Masukkan bilangan: 2
Masukkan bilangan: 3
Jumlahnya adalah : 6
Nilai rata-ratanya : 2.00
Program Menghitung Jumlah dan Banyaknya Data
Script Program Pascal
Output Program Pascal
program contoh4; 
uses wincrt;
var
n, i,byk,jum, bil : integer;
begin
Write(‘Masukkan nilai perulangan : ‘);readln(n);
Writeln;
for i := 1 to n do
begin
write(‘Bilangan ‘,i,’ = ‘);read(bil);
if bil >= 10 then
begin
byk := byk+1;
jum := jum+bil ;
end;
end;
writeln;
writeln(‘banyak bilangan yang >= 10 : ‘,byk);
writeln(‘jumlah bilangan yang >= 10 : ‘,jum);
end.
Masukkan nilai perulangan: 3 
Bilangan 1 = 10
Bilangan 2 = 3
Bilangan 3 = 25
Banyak bilangan yang >= 10 : 2
Jumlah bilangan yang >= 10 : 35

program pembuatan_record;
uses crt;
procedure garis;
begin
writeln(’==============================================’);
end;

type
reckaryawan=record
jab,nip,nama:string;
gol:integer;
gapok,tunj:real;
end;

var pegawai:reckaryawan;
total:real;

begin
clrscr;
writeln(’ LAPORAN PERHITUNGAN GAJI KARYAWAN PT MAJU TAK GENTAR’);
garis;
writeln;
write(’Masukan NIP Karyawan : ‘);readln(pegawai.nip);
write(’Masukan Nama Karyawan : ‘);readln(pegawai.nama);
write(’Golongan[1/2/3] : ‘);readln(pegawai.gol);
garis;
case pegawai.gol of
1:
begin
pegawai.jab:=’Staf dan Tetap’;
pegawai.gapok:=900000;
end;
2:
begin
pegawai.jab:=’Staf dan Kontrak’;
pegawai.gapok:=700000;
end;
3:
begin
pegawai.jab:=’Kontrak’;
pegawai.gapok:=500000;
end;
end;

if pegawai.jab=’Staf dan Tetap’ then
pegawai.tunj:=25/100*pegawai.gapok
else
if pegawai.jab=’Staf dan Kontrak’ then
pegawai.tunj:=10/100*pegawai.gapok
else
pegawai.tunj:=0;
total:=(pegawai.gapok)+(pegawai.tunj);

writeln(’Jabatan Karyawan : ‘,pegawai.jab);
writeln(’Gaji Pokok : ‘,pegawai.gapok:8:0);
writeln(’Tunjangan : ‘,pegawai.tunj:8:0);
garis;
writeln(’Total Gaji Karyawan : ‘,total:8:0);
readln;
end.


Program DataPegawai;
Uses Wincrt;
Type Pegawai = record
NIP       : String[9];
Nama      : String[50];
Golongan  : Char;
Jamkerja  : Real;
End;
Var
Data                 : Pegawai;
Gapok               : Real;
Insentif,Gaber    : Real;
Ul                    : Char;
Begin
  Repeat
    Clrscr;
    Writeln('Entry Data Pegawai PT. Punya gua');
    Writeln('==========================');
    Writeln;
    Write('NIP          : ');Readln(Data.NIP);
    Write('Nama         : ');Readln(Data.Nama);
    Write('Golongan     : ');Readln(Data.Golongan);
    Write('Jam Kerja    : ');Readln(Data.Jamkerja);
    Writeln;
    Writeln;
    Case Data.Golongan of
      '1'  : Gapok:=1000000;
      '2'  : Gapok:=1500000;
      '3'  : Gapok:=2000000;
      Else
        Gapok:=0;
    End;
 
    if Data.Jamkerja>200 then
      Insentif:=(Data.Jamkerja-200)*10000
    else
      Insentif:=0;
    Gaber:=Gapok+Insentif;
    Clrscr;
    Writeln('Laporan Gaji Pegawai');
    Writeln('PT. XYZ');
    Writeln;
    Writeln('============================================================================');
    Writeln('|NIP       | Nama                    | Golongan | Jam Kerja | Gaji         |');
    Writeln('============================================================================');
    Writeln('|',Data.NIP:10,'|',Data.Nama:25,'|',Data.Golongan:10,'|',Data.Jamkerja:11:0,'|',Gaber:14:2,'|');
    Writeln('============================================================================');
    Writeln;
    Write('Mau Ulang Lagi? [Y/T]: ');Readln(Ul);
  Until Upcase(Ul) <> 'Y';
End.
 


================================================================================
Program Gaji_Tunjangan_dan_Pajak;
{Menghitung jumlah gaji berdasarkan golongan, tunjangan anak dan istri, total gaji setelah pajak}
Uses wincrt;
var
nama,jab    : string[20];
noin        : string[10];
golgaj           : char;
stmerit, jmlanak : integer;
gaj,tjbini,tjanak,pajgaj,jmlpajgaj,jmltjgaj,tolgaj,tolgajstpaj : real;
Begin
     clrscr;
     Writeln ('=============================================');
     Writeln ('PERHITUNGAN GAJI DAN TUNJANGAN DAN PAJAK GAJI');
     Writeln ('=============================================');
     Writeln;     
     Writeln ('Isikan Data anda sesuai ketentuan berikut ini : ');
     Writeln ('----------------------------------------------- ');
     Writeln;
     Writeln ('Golongan Gaji :            Status Perkawinan : ');
     Writeln ('a. Rp. 2.000.000.00        1. Kawin ');
     Writeln ('b. Rp. 2.500.000.00        2. Belum kawin');
     Writeln ('c. Rp. 3.000.000.00        3. Cerai ');
     Writeln;
     Write ('Masukkan No karyawan          : ');readln (noin);
     Write ('Masukkan nama anda            : ');readln (nama);
     Write ('Masukkan Jabatan              : ');readln (jab);
     Write ('Masukkan Golongan gaji anda   : ');readln (golgaj);
           case golgaj of
           'a' : begin
                 gaj := 2000000;
                 pajgaj := (2/100);
                 Write ('Status Perkawinan anda : ');readln (stmerit);
                       case stmerit of
                       1 : begin
                           tjbini := (5/100)*gaj;
                           Write ('Jumlah anak         : ');readln (jmlanak);
                                 if jmlanak <= 3 then
                                 tjanak := jmlanak*((2/100)*gaj)
                                 else
                                 tjanak := 3*((2/100)*gaj);
                           end;
                       2 : begin
                           tjbini := 0;
                           tjanak := 0;
                           end;
                       3 : begin
                           tjbini := 0;
                           Write ('Jumlah anak         : ');readln (jmlanak);
                                 if jmlanak <= 3 then
                                 tjanak := jmlanak*((2/100)*gaj)
                                 else
                                 tjanak := 3*((2/100)*gaj);
                           end;
                       else
                           Writeln;
                           Writeln ('================================================================');
                           Writeln;
                           Writeln ('Tunjangan tidak terhitung karena tidak terinput dengan benar !!!');
                       end;
                 end;
           'b' : begin
                 gaj := 2500000;
                 pajgaj := (2.5/100);
                 Write ('Status Perkawinan anda : ');readln (stmerit);
                       case stmerit of
                       1 : begin
                           tjbini := (5/100)*gaj;
                           Write ('Jumlah anak         : ');readln (jmlanak);
                                 if jmlanak <= 3 then
                                 tjanak := jmlanak*((2/100)*gaj)
                                 else
                                 tjanak := 3*((2/100)*gaj);
                           end;
                       2 : begin
                           tjbini := 0;
                           tjanak := 0;
                           end;
                       3 : begin
                           tjbini := 0;
                           Write ('Jumlah anak         : ');readln (jmlanak);
                                 if jmlanak <= 3 then
                                 tjanak := jmlanak*((2/100)*gaj)
                                 else
                                 tjanak := 3*((2/100)*gaj);
                           end;
                       else
                           writeln;
                           Writeln ('================================================================');
                           Writeln;
                           Writeln ('Tunjangan tidak terhitung karena tidak terinput dengan benar !!!');
                       end;
                 end;
           'c' : begin
                 gaj := 3000000;
                 pajgaj := (3/100);
                 Write ('Status Perkawinan anda : ');readln (stmerit);
                       case stmerit of
                       1 : begin
                           tjbini := (5/100)*gaj;
                           Write ('Jumlah anak         : ');readln (jmlanak);
                                 if jmlanak <= 3 then
                                 tjanak := jmlanak*((2/100)*gaj)
                                 else
                                 tjanak := 3*((2/100)*gaj);
                           end;
                       2 : begin
                           tjbini := 0;
                           tjanak := 0;
                           end;
                       3 : begin
                           tjbini := 0;
                           Write ('Jumlah anak         : ');readln (jmlanak);
                                 if jmlanak <= 3 then
                                 tjanak := jmlanak*((2/100)*gaj)
                                 else
                                 tjanak := 3*((2/100)*gaj);
                           end;
                       else
                           writeln;
                           Writeln ('================================================================');
                           Writeln;
                           Writeln ('Tunjangan tidak terhitung karena tidak terinput dengan benar !!!');
                       end;
                 end;
           else
           Writeln;
           Writeln ('=======================================');
           Writeln;
           Writeln ('Maaf, Golongan Gaji tidak terdaftar !!!');
           Writeln;
           end;
     jmltjgaj   := tjbini+tjanak;
     tolgaj     := gaj+jmltjgaj;
     jmlpajgaj  := tolgaj*pajgaj;
     tolgajstpaj := tolgaj-jmlpajgaj;
     Writeln;
     Writeln ('SLIP GAJI -----------------------------------> ');
     Writeln;
     Writeln ('Nama         : ',nama);
     Writeln ('No Karyawan  : ',noin);
     Writeln ('Jabatan      : ',jab);
     Writeln ('+============================================+');
     Writeln ('| Rincian                    | Jumlah        | ');
     Writeln ('+============================================+');
     Writeln ('| Besar Gaji               : | Rp.',gaj:8:0,'   |');
     Writeln ('| Tunjangan istri          : | Rp.',tjbini:8:0,'   |');
     Writeln ('| Tunjangan anak           : | Rp.',tjanak:8:0,'   |');
     Writeln ('| Total gaji               : | Rp.',tolgaj:8:0,'   |');
     Writeln ('| Pajak gaji               : | Rp.',jmlpajgaj:8:0,'   |');
     Writeln ('+----------------------------+---------------+');
     Writeln ('| Total gaji setelah pajak : | Rp.',tolgajstpaj:8:0,'   |');
     Writeln ('+----------------------------+---------------+');
     Writeln ('Program by, w1r0');
     readln;
End.