RSS
email

Program Mesin ATM (Pascal)


program BANK_MADE_ATM;

{Program Mesin ATM
PRA S2 Ilkom UGM
Made Agung Raharja (mdagungraharja@gmail.com)
=========================================================================================}

uses wincrt;

Type
Customer = record
norek :LongInt;
realpin :LongInt;
Saldo :LongInt;
end;
var
FileCustomer : File of Customer;
RecordCustomer : Customer;
lagi,continue,subpil,lanjut :Char;
posisi : integer;
norektuju, salah,t,pilihan,pin,pinb,pinc,i, valtarik,PinA, norek1:longint;


{----------------- Procedure Exit -----------------------------------}
procedure exitt; {proedur untuk keluar program}
begin
clrscr;
writeln('Mau melakukan transaksi lainnya? (Y/N)');
readln(subpil);
if (subpil='n') or (subpil='N') then begin clrscr; writeln('Silakan ambil kartu anda. Terima kasih.');readln; end;
end;

{----------------------- Fungsi rekursif penyebutan bilangan------------------------ }
function Terbilang( x : longint):String;
function Bilang(x : longint):string;
begin
case x of
0: Bilang:='';
1: Bilang:='satu';
2: Bilang:='dua';
3: Bilang:='tiga';
4: Bilang:='empat';
5: Bilang:='lima';
6: Bilang:='enam';
7: Bilang:='tujuh';
8: Bilang:='delapan';
9: Bilang:='sembilan';
10: Bilang:='sepuluh';
11: Bilang:='sebelas';
end;{end case}
end;

begin
if x < 12 then Terbilang := ' ' + Bilang(x) else if x < 20 then terbilang := Terbilang(x-10) + 'belas' else if x < 100 then terbilang := Terbilang(x div 10) + 'puluh' + Terbilang(x mod 10) else if x < 200 then Terbilang := 'seratus' + Terbilang (x -100) else if x < 1000 then terbilang := Terbilang(x div 100) + 'ratus' + Terbilang(x mod 100) else if x < 2000 then Terbilang := 'seribu' + Terbilang (x -1000) else if x < 1000000 then terbilang := Terbilang(x div 1000) + 'ribu' + Terbilang(x mod 1000) else if x < 1000000000 then terbilang := Terbilang(x div 1000000) + 'juta' + Terbilang(x mod 1000000) else terbilang := Terbilang(x div 1000000000) + 'milyar' + Terbilang(x mod 1000000000); end; {------------ function cek ada No rekening --------------------------------------------} function AdaRek(rek:longint):boolean; var ada:boolean; begin ada:=false; reset(FileCustomer); while not eof(FileCustomer) do begin read(FileCustomer, RecordCustomer); if RecordCustomer.norek = rek then begin ada:=true; posisi:=filepos(FileCustomer); {letakkan pointer di eof biar keluar dari looping } seek(FileCustomer, filesize(FileCustomer)); end; end; adarek:=ada; end; {-----------------------------procedure buat acc baru--------------} procedure BuatAccBaru; begin {$I-} Assign(FileCustomer,'ATM.DAT'); rewrite(FileCustomer); {$I+} Lagi:='Y'; while Upcase(Lagi)='Y' do begin clrscr; writeln('..::: Membuat File Baru Data Account :::.. '); writeln('----------------------------------------------'); with RecordCustomer do Begin {proses input no account} write('No Account (9 digit) : '); Readln(norek1); while (norek1<10000000) or (norek1>999999999) do
begin
clrscr;
writeln('Salah');
Write('No account (Min & MAk 9 digit):');Readln(norek1);
end;
if AdaRek(norek1) then
begin
writeln('Data Sudah Ada...');
writeln('Press enter key to continue...');
readln;

end
else
begin
norek:=norek1;
write('PIN (Min & Mak 6 Digit) : ');
Readln(realpin);
{Proses input PIN}
while (realpin<100000) or (realpin>999999) do
begin
writeln('Salah');
Writeln('Masukkan PIN: (6 digit)');Readln(realpin);writeln;
end;

write('Masukkan Saldo Kelipatan 50000 : ');
Readln(saldo);
while (saldo mod 50000<>0) do
begin
Writeln('Masukkan Jumlah Saldo (Rp.) Kelipatan 50.000:');Readln(saldo);writeln;
end;
writeln('Terbilang : ', Terbilang(saldo),'rupiah');

end;
{----------------------rekam file----------------}
write(FileCustomer,RecordCustomer);


{----------------------tutup file----------------}
close(FileCustomer);
end;


GotoXY(5,8);write('Masukkan data lagi (Y/T)');Readln(Lagi);

end;

end;


{------------------------------------Procedure Menambah Data Acc-----------------}
procedure MenambahDataAcc;

begin

Assign(FileCustomer,'ATM.DAT'); {menghubungkan nama dari ekternal file ke dalam suatu file variabel}
{$I-}
Reset(FileCustomer); {Buka File}
{$I+}
if IOResult <> 0 Then Rewrite(FileCustomer);
{----------------------Arahkan petunjuk file ke akhir dari file}
seek(FileCustomer, FileSize(FileCustomer));

Lagi:='Y';
while Upcase(Lagi)='Y' do
begin
clrscr;
with RecordCustomer do
Begin
writeln(' ..::: Menambah Data Account :::.. ');
writeln('----------------------------------------------');
write('No Account (9 digit) : ');
Readln(norek1);
while (norek1<10000000) or (norek1>999999999) do
begin
clrscr;
writeln('Salah');
Write('No account (Min & MAk 9 digit):');Readln(norek1);
end;


if AdaRek(norek1) then
begin
writeln('Data Sudah Ada...');
writeln('Press enter key to continue...');
readln;

end
else
begin
norek:=norek1;
write('PIN (Min & Mak 6 Digit) : ');
Readln(realpin);
while (realpin<100000) or (realpin>999999) do
begin
writeln('Salah');
Writeln('Masukkan PIN: (6 digit)');Readln(realpin);writeln;
end;

write('Masukkan Saldo Kelipatan 50000 : ');
Readln(saldo);
while (saldo mod 50000<>0) do
begin
Writeln('Masukkan Jumlah Saldo (Rp.) Kelipatan 50.000:');Readln(saldo);writeln;

end;
writeln('Terbilang : ', Terbilang(saldo),'rupiah');
{----------------------rekam file----------------}
write(FileCustomer,RecordCustomer);
end;
end;
{----------------------tutup file----------------}
close(FileCustomer);

GotoXY(5,8);write('Masukkan data lagi (Y/T)');Readln(Lagi);
end;

end;

{---------------------- Procedure menghapus Data Account------------------}
Procedure HapusDataAcc;
Var FileTmp : File of Customer;
Lagi,Hapus, ulang: Char;
Ada : Boolean;
i : Integer;

Begin
Ulang:='Y';
Lagi :='Y';
Clrscr;
Repeat
Assign(FileCustomer,'ATM.DAT');
{$I-}
Reset(FileCustomer); {Buka File}
{$I+}

If IOResult<>0 Then
Write('Data Masih Kosong...!')
Else
Begin
Clrscr;
Assign(FileTmp,'atm.tmp');
Rewrite(FileTmp);
Ada:= False;
i:=0;
writeln(' ..::: Meghapus Data Account :::.. ');
writeln('----------------------------------------------');

Write('No Account (9 digit) : ');Readln(norek1);
While (Ada=False) And (i<>Filesize(FileCustomer)) Do
Begin
Seek(FileCustomer,i);
Read(FileCustomer,recordCustomer);
If RecordCustomer.norek=norek1 Then
Ada:=True
Else
Inc(i);
End;
If (Ada=True) Then
Begin
Writeln('PIN : ',RecordCustomer.realpin);
Writeln('Saldo : ',RecordCustomer.saldo:2);
writeln;
Writeln('Data Ini Di Hapus [Y/T]:');Readln(Hapus);
If Upcase(Hapus)='Y' Then
Begin
For i := 1 to Filesize(FileCustomer) Do
Begin
Seek(FileCustomer,i-1);
Read(FileCustomer,RecordCustomer);
If recordcustomer.norek<>norek1 Then
Write(FileTmp,recordcustomer);
End;
Close(FileCustomer);
Assign(FileCustomer,'ATM.Dat');
Erase(FileCustomer);
Assign(FileTmp,'atm.tmp');
Rename(FileTmp,'atm.Dat');
Writeln('Nomor Account "',norek1,'" Sudah Di Hapus!');
End;
End
Else
Begin
Writeln('Nomor Account "',norek1,'" Ini Tidak Ada!');
End;
Writeln('Hapus Data Lagi [Y/T]:');Lagi:=Upcase(Readkey);
End;
Until Lagi<>'Y';
End;


{-----------------------------procedure tampil acc --------------}
procedure TampilAcc;

begin
{$I-}
Assign(FileCustomer,'ATM.DAT');
reset(FileCustomer);
{$I+}

clrscr;
writeln('-------------------------------------');
writeln('No.Acc PIN saldo ');
writeln('--------------------------------------');

while not Eof(FileCustomer) Do
begin
read(FileCustomer, RecordCustomer);
with RecordCustomer do
writeln(norek:5,realpin:10,saldo:11);
end;
writeln('-----------------------------------------');

{----------------------tutup file----------------}
close(FileCustomer);
end;

{------------ function cek pin --------------------------------------------}
function AdaPin(cpin:longint):boolean;
var ada:boolean;
begin
ada:=false;
reset(FileCustomer);
while not eof(FileCustomer) do
begin
read(FileCustomer, RecordCustomer);
if RecordCustomer.realpin = cpin then
begin
ada:=true;
posisi:=filepos(FileCustomer);
{ letakkan pointer di eof biar keluar dari looping }
seek(FileCustomer, filesize(FileCustomer));
end;
end;
adaPin:=ada;

end;


{------------------------------Procedure input pin --------------}

procedure askpin;
begin

Write('Enter your PIN please: ');readln(pin);
end;


{-----------------------------------Procedure Tarik Tunai-------------------}
procedure tariktunai;

begin
Assign(FileCustomer,'ATM.DAT'); {menghubungkan nama dari ekternal file ke dalam suatu file variabel}
Reset(FileCustomer); {Buka File}
pin:=RecordCustomer.Realpin;
Read(FileCustomer, RecordCustomer);

if adapin(pin) then
begin

repeat
clrscr;
Writeln('AKEPI BANK ATM');
Writeln('TARIK TUNAI');
Writeln;
Writeln('1. 100.000 4. 1.500.000');
Writeln('2. 200.000 5. 2.500.000');
Writeln('3. 500.000 6. Other value');
Writeln;
Writeln('Enter your choice please: ');Readln(pilihan);
writeln('pin', RecordCustomer.Realpin);
Case pilihan of
1: valtarik:= 100000;
2: valtarik:= 200000;
3: valtarik:= 500000;
4: valtarik:= 1500000;
5: valtarik:= 2500000;
6: begin
clrscr;
writeln('Enter the value:');
Readln(valtarik);
while (valtarik mod 50000<>0) or (valtarik>5000000) do {penarikan mak 5juta}
begin
Writeln('Enter the value (Kelipatan Rp.50.000) :');Readln(valtarik);writeln;
end;
end;
else Writeln('Choice is not available!');
end;
until pilihan<7; while RecordCustomer.saldo-valtarik<=25000 do begin repeat clrscr; Writeln('AKEPI BANK ATM'); Writeln('TARIK TUNAI'); Writeln; Writeln('1. 100.000 4. 1.500.000'); Writeln('2. 200.000 5. 2.500.000'); Writeln('3. 500.000 6. Other value'); Writeln; Writeln('Saldo tidak mencukupi.'); Writeln('Enter your choice please: ');Readln(pilihan); Case pilihan of 1: valtarik:= 100000; 2: valtarik:= 200000; 3: valtarik:= 500000; 4: valtarik:= 1500000; 5: valtarik:= 2500000; 6: begin clrscr; writeln('Enter the value:'); Readln(valtarik); while (valtarik mod 50000<>0) or (valtarik>5000000) do {penarikan mak 5juta}
begin
Writeln('Enter the value (Kelipatan Rp.50.000) :');Readln(valtarik);writeln;
end;
end;
else Writeln('Choice is not available!');
end;
until pilihan<7; end; if RecordCustomer.saldo-valtarik>25000 then
RecordCustomer.saldo:=RecordCustomer.saldo-valtarik;
seek(FileCustomer,posisi-1);
Write(FileCustomer, RecordCustomer);
end;
clrscr;
Writeln('Silakan ambil uang anda.');
Writeln('Press enter key to continue...');
readln;
exitt;
{----------------------tutup file----------------}
close(FileCustomer);
end;

{--------------------- Ganti Pin -----------------------}
procedure gantipin;

begin
clrscr;
Assign(FileCustomer,'ATM.DAT');
Reset(FileCustomer);
Writeln('BANK MADE ATM');
Writeln('GANTI PIN');
Writeln;
Writeln;
Writeln('Masukkan PIN anda sekarang:');
Writeln;
Readln(pin);
Writeln;

Read(FileCustomer, RecordCustomer);

if adaPin(pin) then
begin
clrscr;
Writeln('BANK MADE ATM');
Writeln('GANTI PIN');
Writeln;
Writeln('Access Granted!');
Writeln('Masukkan PIN anda yang baru:');
Writeln;
Readln(pinb);
while (pinb<100000) or (pinb>999999) do
begin
writeln('Salah');
Writeln('Masukkan PIN: (6 digit)');Readln(pinb);writeln;
end;
clrscr;
Writeln('BANK MADE ATM');
Writeln('GANTI PIN');
Writeln;
Writeln;
Writeln('Masukkan PIN anda yang baru sekali lagi:');
Writeln;
Readln(pinc);

if (pinb=pinc) then
begin
RecordCustomer.realpin:=pinb;
{seek(FileCustomer, I-1);}
seek(FileCustomer,posisi-1);
Write(FileCustomer, RecordCustomer);

clrscr;
writeln('PIN sudah diubah.');
end
else
begin
clrscr;
writeln('PIN salah. PIN tidak diubah.');
end;
end
else
begin
clrscr;
writeln('PIN salah. PIN tidak diubah.');
end;

close(FileCustomer);
clrscr;
writeln;
Writeln('Press enter key to continue...');
readln;
exitt;


end;

{-------------------------- PROCEDURE TRANSFER ---------------------------------------}
procedure transfer;
begin
clrscr;
Assign(FileCustomer,'ATM.DAT');
Reset(FileCustomer);
pin:=RecordCustomer.Realpin;
Read(FileCustomer, RecordCustomer);

if adapin(pin) then
begin

Writeln('BANK MADE ATM');
Writeln('TRANSFER');
Writeln;
Writeln;
Writeln('Masukkan dana yang mau ditransfer:');
Writeln;
Readln(valtarik);
while (valtarik mod 50000<>0) or (valtarik>7000000) do {penarikan mak 5juta}
begin
Writeln('Enter the value (Kelipatan Rp.50.000) :');Readln(valtarik);writeln;
end;

while RecordCustomer.saldo-valtarik<=25000 do begin clrscr; Writeln('BANK MADE ATM'); Writeln('TRANSFER'); Writeln; Writeln('Saldo anda tidak mencukupi!'); Writeln('Masukkan dana yang mau ditransfer:'); Writeln; Readln(valtarik); while (valtarik mod 50000<>0) or (valtarik>7000000) do {penarikan mak 5juta}
begin
Writeln('Enter the value (Kelipatan Rp.50.000) :');Readln(valtarik);writeln;
end;
end;

clrscr;
Writeln('BANK MADE ATM');
Writeln('TRANSFER');
Writeln;
Writeln;
Writeln('Masukkan no rekening yang dituju: (9 digit)');
Writeln;
Readln(norektuju);

if (norektuju<999999999) or (norektuju>999999999) then
begin
clrscr;
Writeln('BANK MADE ATM');
Writeln('TRANSFER');
Writeln;
Writeln('No rekening yang dimasukkan salah!');
Writeln('Masukkan no rekening yang dituju: (9 digit)');
Writeln;
Readln(norektuju);
end;

if RecordCustomer.saldo-valtarik>25 then
RecordCustomer.saldo:=RecordCustomer.saldo-valtarik;
seek(FileCustomer,posisi-1);
write(FileCustomer, RecordCustomer);

end;

clrscr;
Writeln('Transfer selesai dilakukan.');
Writeln('Press enter key to continue...');
readln;
exitt;
{----------------------tutup file----------------}
close(FileCustomer);
end;

{-------------------------- procedure info saldo -------------------------}
procedure infosaldo;
begin
clrscr;
{$I-}
Assign(FileCustomer,'ATM.DAT');
reset(FileCustomer);
{$I+}
Writeln('BANK MADE ATM');
Writeln('INFORMASI SALDO');
Writeln;
Writeln;
Writeln('Saldo rekening anda sebesar:');
Writeln('');

pin:=RecordCustomer.Realpin;
Read(FileCustomer, RecordCustomer);
if adapin(pin) then
begin
Writeln('Rp. ',RecordCustomer.saldo);
writeln('Terbilang : ', Terbilang(RecordCustomer.saldo),' rupiah');
Writeln;
Writeln('Press enter key to continue...');
readln;

end;
{----------------------tutup file----------------}
close(FileCustomer);
exitt;
end;



{*********** progra utama***********************}
var
pilih :byte;
pinOke:boolean;


begin
while true do
begin
clrscr;
writeln('************************************');
Writeln('* BANK MADE *');
Writeln('* ADMINISTRATOR FORM *');
Writeln('************************************');
Writeln;

GotoXY(5,5);writeln('1.Buat File Account Baru');
GotoXY(5,6);writeln('2.Tambah Account Baru');
GotoXY(5,7);writeln('3.Menampilkan Data');
GotoXY(5,8);writeln('4.Menghapus Data');
GotoXY(5,9);writeln('5.Transaksi ATM');

pilih := 0;
while (Pilih<1) or (Pilih >5) do
begin
GotoXY(5,12);Write('Pilih Nomor(1-5)');Readln(Pilih);
if (Pilih <1) or (Pilih >5) then
write(^G);
end;

case Pilih of
1 : BuatAccBaru;
2 : MenambahDataAcc;
3 : Begin
TampilAcc;
writeln('Tekan enter untuk kembali ke menu');
readln;
end;
4 : hapusDataAcc;

5 :begin
clrscr;
writeln('..:: SELAMAT DATANG DI ATM BANK MADE ::..');
writeln('-----------------------------------------');

Assign(FileCustomer,'ATM.DAT');
{$I-} {pengecekan I/O disable}
Reset(FileCustomer);
{$I+}
pinOke:=false;
for i:=1 to 3 Do
begin

askPin;
if adaPin(pin) then
begin
pinOke:=true;
writeln('Access granted!');
salah:=0;writeln;
writeln('Press enter key to continue...');
Readln;
i:=3;
end
else
begin
inc(salah);
writeln('Wrong PIN!');
writeln;
if salah>=3 then
begin
writeln('Your card is blocked!');
exit;
end;
end;
end;

if not pinOke then exit;

{**************MENU AWAL***************}

Repeat
Repeat
clrscr;
writeln('**************************************');
Writeln('* BANK MADE ATM *');
Writeln('* MAIN MENU *');
writeln('**************************************');
Writeln;
Writeln('1. Tarik Tunai 3. Informasi Saldo');
Writeln('2. Transfer 4. Ganti PIN ');
Writeln('0. Batalkan transaksi');
Writeln;
Writeln('Enter your choice please: ');Readln(pilihan);

Case pilihan of
0: exitt;
1: tariktunai;
2: transfer;
3: infosaldo;
4: gantipin;
end;{end case}

until pilihan<4; until (subpil='n') or (subpil='N'); end; end; end; close(FileCustomer); {tutup file dan menuskannya ke penyuimpan sekunder} end.

Bookmark and Share

0 komentar:

Posting Komentar

 

Friends

ON-LINE