Program hitung;
uses wincrt;
const m:longint=5;
type barang=record
kode:longint;
nama:string;
harga:longint;
berat:longint;
stok:longint;
pembelian:longint;
end;
function cekharga(uang,harga:longint):boolean;
var
cek:boolean;
begin
cek:=false;
if (uang>=harga) then
begin
cek:=true;
end;
cekharga:=cek;
end;
function cekberat(berat,barang:longint):boolean;
var
cek:boolean;
begin
cek:=false;
if (barang>=berat) then
begin
cek:=true;
end;
cekberat:=cek;
end;
function cekstok(stok:longint):boolean;
var
cek:boolean;
begin
cek:=true;
if (stok=0) then
begin
cek:=false;
end;
cekstok:=cek;
end;
procedure hitungstok(var stok:longint);
begin
stok:=stok-1;
end;
procedure beli(var uang:longint; harga:longint );
begin
uang:=uang-harga;
end;
procedure penuh(var kranjang:longint; berat:longint );
begin
kranjang:=kranjang-berat;
end;
var
product,simpan:array [1..50] of barang;
i,n,uang,kranjang,temp:longint;
pil:string;
begin
temp:=0;
product[1].kode:=1;
product[1].nama:=('coke');
product[1].harga:=5000;
product[1].berat:=350;
product[1].stok:=5;
product[2].kode:=2;
product[2].nama:=('sprite');
product[2].harga:=3500;
product[2].berat:=275;
product[2].stok:=7;
product[3].kode:=3;
product[3].nama:=('bear');
product[3].harga:=6000;
product[3].berat:=400;
product[3].stok:=9;
product[4].kode:=4;
product[4].nama:=('fanta');
product[4].harga:=4000;
product[4].berat:=275;
product[4].stok:=4;
product[5].kode:=5;
product[5].nama:=('redbull');
product[5].harga:=6000;
product[5].berat:=350;
product[5].stok:=5;
for i:= 1 to m do
begin
simpan[i]:=product[i];
simpan[i].pembelian:=0;
end;
writeln('|-------------------------------------|');
writeln('|kode |nama |harga |berat |stok |');
writeln('|-------------------------------------|');
writeln('| 1 |coke |5000 |350 | ',product[1].stok,' |');
writeln('| 2 |sprite |3500 |275 | ',product[2].stok,' |');
writeln('| 3 |bear |6000 |400 | ',product[3].stok,' |');
writeln('| 4 |fanta |4000 |275 | ',product[4].stok,' |');
writeln('| 5 |redbull |6000 |350 | ',product[5].stok,' |');
writeln('|-------------------------------------|');
writeln;
writeln;
write('masukan jumlah uang anda : ');readln(uang);
write('masukan kapasitas keranjang anda : ');readln(kranjang);
writeln;
write('apakah anda ingin berbelanja (y/t) ');readln(pil);
writeln;
while (pil='y') do
begin
write('masukan kode minuman yg ingin dibeli : ');readln(n);
writeln;
if (n<=m) then
begin
if (cekstok(product[n].stok)=true) then
begin
if (cekberat(product[n].berat,kranjang)=true) and (cekharga(uang,product[n].harga)=true) then
begin
beli(uang,product[n].harga);
penuh(kranjang,product[n].berat);
hitungstok(product[n].stok);
simpan[n].pembelian:=simpan[n].pembelian+1;
temp:=temp+1;
write('apakah anda ingin berbelanja lagi (y/t) ');readln(pil);
writeln;
end
else
begin
clrscr;
writeln('maav anda tidak bisa melakukan transaksi');
writeln('terima kasih');
writeln;
writeln('sisa uang anda : ',uang);
writeln('sisa kapasitas kranjang : ',kranjang);
writeln;
if (temp>0) then
begin
writeln('barang yg telah dibeli : ');
for i:= 1 to m do
begin
if (simpan[i].pembelian>0) then
begin
writeln(simpan[i].nama,' jumlah yg dibeli ',simpan[i].pembelian);
end
end;
end
else
writeln('tidak ada barang yg dibeli');
writeln;
writeln;
writeln('sisa minuman');
writeln;
writeln('|-------------------------------------|');
writeln('|kode |nama |harga |berat |stok |');
writeln('|-------------------------------------|');
writeln('| 1 |coke |5000 |350 | ',product[1].stok,' |');
writeln('| 2 |sprite |3500 |275 | ',product[2].stok,' |');
writeln('| 3 |bear |6000 |400 | ',product[3].stok,' |');
writeln('| 4 |fanta |4000 |275 | ',product[4].stok,' |');
writeln('| 5 |redbull |6000 |350 | ',product[5].stok,' |');
writeln('|-------------------------------------|');
writeln;
pil:=' ';
end;
end
else
begin
writeln('maav stok kosong');
writeln;
write('apakah anda ingin berbelanja lagi (y/t) ');readln(pil);
writeln;
end;
end
else
begin
writeln('maaf kode barang tidak terdaftar');
writeln;
write('apakah anda ingin berbelanja lagi (y/t) ');readln(pil);
writeln;
end;
end;
if (pil='t') then
begin
clrscr;
writeln('terima kasih');
writeln;
writeln('sisa uang anda : ',uang);
writeln('sisa kapasitas kranjang : ',kranjang);
writeln;
if (temp>0) then
begin
writeln('barang yg telah dibeli : ');
for i:= 1 to m do
begin
if (simpan[i].pembelian>0) then
begin
writeln(simpan[i].nama,' jumlah yg dibeli ',simpan[i].pembelian);
end
end;
end
else
writeln('tidak ada barang yg dibeli');
writeln;
writeln;
writeln('sisa minuman');
writeln;
writeln('|-------------------------------------|');
writeln('|kode |nama |harga |berat |stok |');
writeln('|-------------------------------------|');
writeln('| 1 |coke | 5000 | 350 | ',product[1].stok,' |');
writeln('| 2 |sprite | 3500 | 275 | ',product[2].stok,' |');
writeln('| 3 |bear | 6000 | 400 | ',product[3].stok,' |');
writeln('| 4 |fanta | 4000 | 275 | ',product[4].stok,' |');
writeln('| 5 |redbull | 6000 | 350 | ',product[5].stok,' |');
writeln('|-------------------------------------|');
writeln;
end;
end.
ada nga program penjualan tiket pesawat
ReplyDelete