Senin, 17 Oktober 2016

Prototipe Program ATM

Setelah membuat UseCase Diagram coba kita buat prototype dari mesin ATM. Untuk melihat use case diagram serta sequence diagramnya dapat dilihat pada http://exodblog.blogspot.sg/2016/09/use-case-dan-interaction-diagram-untuk.html

#include
#include
#include
#include
using namespace std;

class account
{
	int acno;
	char name[50];
	int deposit;
public:
	void create_account();	
	void show_account() const;
	void dep(int);
	void draw(int);
	void report() const;
	int retacno() const;
	int retdeposit() const;	
};        

void account::create_account()
{
	cout<<"\nMasukkan no rekening. :";
	cin>>acno;
	cout<=500 ) : ";
	cin>>deposit;
	cout<<"\n\n\nAkun berhasil dibuat..\n";
}

void account::show_account() const
{
	cout<<"\nNo. rekening : "<>ch;
		system("cls");
		switch(ch)
		{
		case '1':
			write_account();
			break;
		case '2':
			cout<<"\n\n\tNo. rekening : "; cin>>num;
			deposit_withdraw(num, 1);
			break;
		case '3':
			cout<<"\n\n\tNo. rekening : "; cin>>num;
			deposit_withdraw(num, 2);
			break;
		case '4': 
			cout<<"\n\n\tNo. rekening : "; cin>>num;
			display_sp(num);
			break;
		case '5':
			display_all();
			break;
		 case '6':
			cout<<"\n\n\tBye ...";
			break;
		 default :cout<<"\a";
		}
		cin.ignore();
		cin.get();
	}while(ch!='6');
	return 0;
}

//    	write to file 

void write_account()
{
	account ac;
	ofstream outFile;
	outFile.open("account.txt",ios::binary|ios::app);
	ac.create_account();
	outFile.write(reinterpret_cast (&ac), sizeof(account));
	outFile.close();
}

//    	Menampilkan saldo akun spesifik

void display_sp(int n)
{
	account ac;
	bool flag=false;
	ifstream inFile;
	inFile.open("account.txt",ios::binary);
	if(!inFile)
	{
		cout<<"File error !";
		return;
	}
	cout<<"\nDETAIL SALDO\n";

    	while(inFile.read(reinterpret_cast (&ac), sizeof(account)))
	{
		if(ac.retacno()==n)
		{
			ac.show_account();
			flag=true;
		}
	}
	inFile.close();
	if(flag==false)
		cout<<"\n\nTidak ditemukan akun ..";
}

//    	Menampilkan saldo semua akun 

void display_all()
{
	account ac;
	ifstream inFile;
	inFile.open("account.txt",ios::binary);
	if(!inFile)
	{
		cout<<"File error !";
		return;
	}
	cout<<"\n\n\t\tDAFTAR AKUN\n\n";
	cout<<"====================================================\n";
	cout<<"A/c no.      NAME       Saldo\n";
	cout<<"====================================================\n";
	while(inFile.read(reinterpret_cast (&ac), sizeof(account)))
	{
		ac.report();
	}
	inFile.close();
}

//    	Fungsi deposit dan tarik uang 

void deposit_withdraw(int n, int option)
{
	int amt;
	bool found=false;
	account ac;
	fstream File;
	File.open("account.txt", ios::binary|ios::in|ios::out);
	if(!File)
	{
		cout<<"File error !";
		return;
	}
	while(!File.eof() && found==false)
	{
		File.read(reinterpret_cast (&ac), sizeof(account));
		if(ac.retacno()==n)
		{
			ac.show_account();
			if(option==1)
			{
				cout<<"\n\nMasukkan jumlah uang : ";
				cin>>amt;
				ac.dep(amt);
			}
			if(option==2)
			{
				cout<<"\n\nMasukkan jumlah uang : ";
				cin>>amt;
				int bal=ac.retdeposit()-amt;
				if(bal<500)
					cout<<"Saldo tidak cukup";
				else
					ac.draw(amt);
			}
			int pos=(-1)*static_cast(sizeof(ac));
			File.seekp(pos,ios::cur);
			File.write(reinterpret_cast (&ac), sizeof(account));
			cout<<"\n\n\t Data diperbarui";
			found=true;
	       }
         }
	File.close();
	if(found==false)
		cout<<"\n\n Data tidak ditemukan ";
}

void intro()
{
	cout<<"\n\n\n ATM BANK MANAGEMENT SYSTEM";
	cin.get();
}
by : Andreas Galang A (5114100153)

0 komentar:

Posting Komentar

luvne.com resepkuekeringku.com desainrumahnya.com yayasanbabysitterku.com