Pascal yang digunakan pada Delphi yang menggunakan Consol Aplication
Pada contoh program ini gue bakalan berbagi info tentang listing/koddingan program yang menggunakan tipe data berupa :
1. Array
2. Record
3. Procedure
4. Function
Berikut listing programnya :
program FP_Penjualan;
{$APPTYPE CONSOLE}
uses
SysUtils;
Type Kasir = record
no_trans, tgl, nama, nm_brg : String[25];
kd_brg, jml : integer;
hrg, tot : real;
End;
Data = Array [1..100] of Kasir;
{Procedure unutk menampilkan judul}
Procedure judul;
begin
Writeln(' IF IPHONE SHOP ');
Writeln(' Jl.Srijaya Negara Bukit Besar Palembang ');
end;
Procedure menu;
begin
Writeln('==========================================');
Writeln;
Writeln (' Data Barang dan harga ');
Writeln('==========================================');
writeln;
Writeln ('1. Iphone 6 Rp. 11000000 ');
Writeln ('2. Iphone 6+ Rp. 12000000');
Writeln ('3. Iphone 5+ Rp. 6500000');
Writeln ('4. Iphone 5C Rp. 5500000');
Writeln ('5. Iphone 4S Rp. 2000000');
Writeln ('6. Iphone 4G Rp. 1800000');
Writeln ('7. Iphone 3GS Rp. 1000000');
Writeln ('8. Iphone 3G Rp. 800000');
end;
{Procedur Inpu data}
Procedure Input1 (var n : integer);
begin
Write ('Masukkan banyak data : '); readln (n);
writeln;
end;
Procedure form;
begin
writeln;
writeln(' Form Transaksi ');
writeln;
end;
Procedure Input2 (n : integer; var jual : Data);
var
i:integer;
begin
for i:= 1 to n do
begin
Writeln('Data Ke-',i);
Writeln;
begin
Write('No Transaksi : ');Readln(jual[i].no_trans);
Write('Tanggal : ');Readln(jual[i].tgl);
Write('Nama Pembeli : ');Readln(jual[i].nama);
Write('Kode Barang : ');Readln(jual[i].kd_brg);
Write ('Jumlah Beli : ');Readln(jual[i].jml);
end;
writeln;
end;
end;
{Procedure Proses perhitngan perulangan percabangan dan perulangan}
procedure proses (n : integer; var jual : data);
var
i : integer;
begin
for i:= 1 to n do
if jual[i].kd_brg = 1 then
begin
jual[i].nm_brg :='Iphone 6';
jual[i].hrg :=11000000;
end
else
if jual[i].kd_brg = 2 then
begin
jual[i].nm_brg :='Iphone 6+';
jual[i].hrg :=12000000;
end
else
if jual[i].kd_brg = 3 then
begin
jual[i].nm_brg :='Iphone 5+';
jual[i].hrg :=6500000;
end
else
if jual[i].kd_brg = 4 then
begin
jual[i].nm_brg :='Iphone 5C';
jual[i].hrg :=5500000;
end
else
if jual[i].kd_brg = 5 then
begin
jual[i].nm_brg :='Iphone 4S';
jual[i].hrg :=2000000;
end
else
if jual[i].kd_brg = 6 then
begin
jual[i].nm_brg :='Iphone 4G';
jual[i].hrg :=1800000;
end
else
if jual[i].kd_brg = 7 then
begin
jual[i].nm_brg := 'Iphone 3GS';
jual[i].hrg := 1000000;
end
else
if jual[i].kd_brg = 8 then
begin
jual[i].nm_brg := 'Iphone 3G';
jual[i].hrg := 800000;
end;
end;
procedure hitung1 (n : integer; var jual : Data);
var
i : integer;
begin
for i:= 1 to n do
begin
jual[i].tot:=jual[i].jml*jual[i].hrg;
end;
end;
function hitung2 (n : integer; jml_penjualan : real; jual : data ) : real;
var
i: integer;
begin
for i:= 1 to n do
jml_penjualan:=jml_penjualan+jual[i].tot;
hitung2:=jml_penjualan;
end;
procedure kolom;
begin
Writeln('============ Cetak Transaksi =============');
Writeln('==========================================');
end;
{Procedure Output}
procedure output (n : integer; jual : Data);
var
i : integer;
begin
For i := 1 to n do
begin
write(i);
Writeln(' No Transaksi : ',jual[i].no_trans);
Writeln(' Tgl : ',jual[i].tgl);
Writeln(' Nama Pembeli : ',jual[i].nama);
Writeln(' Nama Barang : ',jual[i].nm_brg);
Writeln(' Harga : ',jual[i].hrg:0:0);
Writeln(' Jumlah : ',jual[i].jml);
Writeln(' Total Harga : ',jual[i].tot:0:0);
writeln;
end;
end;
Procedure output2 ( n : integer; jml_penjualan : real);
begin
Writeln('==========================================');
Writeln('Jumlah Transaksi : ', n);
Writeln('Jumlah Penjualan : Rp.',jml_penjualan:0:0);
writeln;
End;
Var
jual : Data;
n: Integer;
jml_penjualan : real;
{Program Utama}
begin
{ TODO -oUser -cConsole Main : Insert code here }
judul;
menu;
Writeln;
input1 (n);
form;
input2 (n,jual);
proses (n,jual);
hitung1 (n,jual);
jml_penjualan:= hitung2 (n,jml_penjualan,jual);
Writeln;
Judul;
writeln;
Kolom;
output (n,jual);
output2 (n,jml_penjualan);
readln;
end.
Hasil Outputnya
Pada contoh program ini gue bakalan berbagi info tentang listing/koddingan program yang menggunakan tipe data berupa :
1. Array
2. Record
3. Procedure
4. Function
Berikut listing programnya :
program FP_Penjualan;
{$APPTYPE CONSOLE}
uses
SysUtils;
Type Kasir = record
no_trans, tgl, nama, nm_brg : String[25];
kd_brg, jml : integer;
hrg, tot : real;
End;
Data = Array [1..100] of Kasir;
{Procedure unutk menampilkan judul}
Procedure judul;
begin
Writeln(' IF IPHONE SHOP ');
Writeln(' Jl.Srijaya Negara Bukit Besar Palembang ');
end;
Procedure menu;
begin
Writeln('==========================================');
Writeln;
Writeln (' Data Barang dan harga ');
Writeln('==========================================');
writeln;
Writeln ('1. Iphone 6 Rp. 11000000 ');
Writeln ('2. Iphone 6+ Rp. 12000000');
Writeln ('3. Iphone 5+ Rp. 6500000');
Writeln ('4. Iphone 5C Rp. 5500000');
Writeln ('5. Iphone 4S Rp. 2000000');
Writeln ('6. Iphone 4G Rp. 1800000');
Writeln ('7. Iphone 3GS Rp. 1000000');
Writeln ('8. Iphone 3G Rp. 800000');
end;
{Procedur Inpu data}
Procedure Input1 (var n : integer);
begin
Write ('Masukkan banyak data : '); readln (n);
writeln;
end;
Procedure form;
begin
writeln;
writeln(' Form Transaksi ');
writeln;
end;
Procedure Input2 (n : integer; var jual : Data);
var
i:integer;
begin
for i:= 1 to n do
begin
Writeln('Data Ke-',i);
Writeln;
begin
Write('No Transaksi : ');Readln(jual[i].no_trans);
Write('Tanggal : ');Readln(jual[i].tgl);
Write('Nama Pembeli : ');Readln(jual[i].nama);
Write('Kode Barang : ');Readln(jual[i].kd_brg);
Write ('Jumlah Beli : ');Readln(jual[i].jml);
end;
writeln;
end;
end;
{Procedure Proses perhitngan perulangan percabangan dan perulangan}
procedure proses (n : integer; var jual : data);
var
i : integer;
begin
for i:= 1 to n do
if jual[i].kd_brg = 1 then
begin
jual[i].nm_brg :='Iphone 6';
jual[i].hrg :=11000000;
end
else
if jual[i].kd_brg = 2 then
begin
jual[i].nm_brg :='Iphone 6+';
jual[i].hrg :=12000000;
end
else
if jual[i].kd_brg = 3 then
begin
jual[i].nm_brg :='Iphone 5+';
jual[i].hrg :=6500000;
end
else
if jual[i].kd_brg = 4 then
begin
jual[i].nm_brg :='Iphone 5C';
jual[i].hrg :=5500000;
end
else
if jual[i].kd_brg = 5 then
begin
jual[i].nm_brg :='Iphone 4S';
jual[i].hrg :=2000000;
end
else
if jual[i].kd_brg = 6 then
begin
jual[i].nm_brg :='Iphone 4G';
jual[i].hrg :=1800000;
end
else
if jual[i].kd_brg = 7 then
begin
jual[i].nm_brg := 'Iphone 3GS';
jual[i].hrg := 1000000;
end
else
if jual[i].kd_brg = 8 then
begin
jual[i].nm_brg := 'Iphone 3G';
jual[i].hrg := 800000;
end;
end;
procedure hitung1 (n : integer; var jual : Data);
var
i : integer;
begin
for i:= 1 to n do
begin
jual[i].tot:=jual[i].jml*jual[i].hrg;
end;
end;
function hitung2 (n : integer; jml_penjualan : real; jual : data ) : real;
var
i: integer;
begin
for i:= 1 to n do
jml_penjualan:=jml_penjualan+jual[i].tot;
hitung2:=jml_penjualan;
end;
procedure kolom;
begin
Writeln('============ Cetak Transaksi =============');
Writeln('==========================================');
end;
{Procedure Output}
procedure output (n : integer; jual : Data);
var
i : integer;
begin
For i := 1 to n do
begin
write(i);
Writeln(' No Transaksi : ',jual[i].no_trans);
Writeln(' Tgl : ',jual[i].tgl);
Writeln(' Nama Pembeli : ',jual[i].nama);
Writeln(' Nama Barang : ',jual[i].nm_brg);
Writeln(' Harga : ',jual[i].hrg:0:0);
Writeln(' Jumlah : ',jual[i].jml);
Writeln(' Total Harga : ',jual[i].tot:0:0);
writeln;
end;
end;
Procedure output2 ( n : integer; jml_penjualan : real);
begin
Writeln('==========================================');
Writeln('Jumlah Transaksi : ', n);
Writeln('Jumlah Penjualan : Rp.',jml_penjualan:0:0);
writeln;
End;
Var
jual : Data;
n: Integer;
jml_penjualan : real;
{Program Utama}
begin
{ TODO -oUser -cConsole Main : Insert code here }
judul;
menu;
Writeln;
input1 (n);
form;
input2 (n,jual);
proses (n,jual);
hitung1 (n,jual);
jml_penjualan:= hitung2 (n,jml_penjualan,jual);
Writeln;
Judul;
writeln;
Kolom;
output (n,jual);
output2 (n,jml_penjualan);
readln;
end.
Hasil Outputnya
Semoga membantu
Tidak ada komentar:
Posting Komentar