banking system

Pages: 12
Hi i need some help for my program which is banking system

I have two problems which is the objective of the program, but i cannot do

First Problem : The objective of the program is to create first or open an account before activating the other options. i cannot do it

Second Problem: If the user will deposit the money, automatically there is a 500 minimum or initial deposit, and if he will withdraw, the 500 will remain, there is should be a 500 still there,

Here is the code guys:

#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>


//void heading(void);



void main (void)
{
char name[32];
float bal,x;
int c1,c2, mdeposit=500;
c2=bal=0;
c1=1;
while (c1 != 0)
{
clrscr();

//heading();
cout<<"========================================\n";
cout<<"=Welcome to Gomez Bank=\n";
cout<<"========================================\n";
cout<<"1. Open Bank Account\n";
cout<<"2. Check Balance\n";
cout<<"3. Deposit\n";
cout<<"4. Withdraw\n";
cout<<"5. Close Bank Account\n";
cout<<"6. Exit\n";
cout<<"Please enter your transaction: ";

cin>>c1;
clrscr();


switch(c1)
{
case 1:

cout<<"\nPlease Enter Your Full Name: ";
gets(name);
do
{
clrscr();
cout<<"\n\n\t\t\tNote 500 is the minimuim deposit";
cout<<"\n\nPlease Enter Your Initial Deposit: ";
cin>>x;
bal = bal + x;
getch();
}while(bal < 500);
mdeposit = 500;
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else if(c2 ==1){

break;
}

case 2:
cout<<"Your current balance is: "<<bal<<"\n";
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
break;


case 3:
cout<<"Enter the value you would like to deposit: ";
cin>>x;
while(x<=0)
{
cout<<"The value you've entered is invalid. \nPlease try again: ";
cin>>x;
}
bal = bal + x;
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
break;


case 4:
cout<<"Enter the value you would like to withdraw ";
cin>>x;
while (x > bal || x <=0)
{
cout<<"The value you've entered is invalid. \nPlease try again: ";
cin>>x;
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
}
bal = bal - x;
break;


case 5:


case 6:
c1 = 0;
break;
}
};

cout<<"\n\n\n\t\tThank you for using Gomez Banking Systems!";
getch();

}





Thanks in advance
Hi david123456!
There're some tips for you:
Can you give us your example output that you should have?
Put your code into code format tags - the <> button on the right. This makes your code easier to read and more people will ready to help you.

Hope all goes well...
Hi,

Thanks a lot for replying my message, uhm i really don't know how to format tags, since i am newbie in programming, hehe

The output should be the menu first, with 6 choices

1.open bank account
2. check balance
3.deposit
4.withdraw
5.close bank account
6.exit

the objective is to display this 6 items but first they need to choose number 1 which is the open bank account, if they choose other number, it will come up with error and it will just comeback to the menu that is my first problem, cant do it, second problem after creating a bank account, all the options will be enabled but they cannot create a bank account again, they should close it first, third problem if they deposit, there will be 500 minimuim deposit, and if they withdraw they cannot withdraw exceeding to that 500, i will post more organized code, i had here a algorithm for the initial deposit, but its not working


Please i need some help, thanks a lot

#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>






void main (void)
{
char name[32];
float bal,x;
int c1,c2;
c2=bal=0;
c1=1;
while (c1 != 0)
{
clrscr();


cout<<"========================================\n";
cout<<"=Welcome to Gomez Bank=\n";
cout<<"========================================\n";
cout<<"1. Open Bank Account\n";
cout<<"2. Check Balance\n";
cout<<"3. Deposit\n";
cout<<"4. Withdraw\n";
cout<<"5. Close Bank Account\n";
cout<<"6. Exit\n";
cout<<"Please enter your transaction: ";

cin>>c1;
clrscr();


switch(c1)
{
case 1:

cout<<"\nPlease Enter Your Full Name: ";
gets(name);


clrscr();
do
{
cout<<"\n\n\t\t\tNote 500 is the minimuim deposit";
cout<<"\n\nPlease Enter Your Initial Deposit: ";
cin>>x;
}while(x < 500);
bal = bal + x;
getch();

cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else if(c2 ==1){

break;
}

case 2:
cout<<"Your current balance is: "<<bal<<"\n";
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
break;


case 3:
cout<<"Enter the value you would like to deposit: ";
cin>>x;
while(x<=0)
{
cout<<"The value you've entered is invalid. \nPlease try again: ";
cin>>x;
}
bal = bal + x;
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
break;


case 4:
cout<<"Enter the value you would like to withdraw ";
cin>>x;

while (x > bal || x <=0 || x-bal < 500)
{

cout<<"The value you've entered is invalid. \nPlease try again: ";
cin>>x;
}
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
bal = bal - x;
break;


case 5:


case 6:
c1 = 0;
break;
}
};

cout<<"\n\n\n\t\tThank you for using Gomez Banking Systems!";
getch();

}
Just click 'Edit' to enter edit mode, you'll see a format menu on the right. Click <>, then put your code into the tabs you've just received (Eg : <code> Code </code>) And your code is ready !!!!


And anything else? Only menu items? Final output results?
Tell us the your example expected output from your mind.
Last edited on
Your program demonstration algorithm:

the objective is to display this 6 items but first they need to choose number 1 which is the open bank account, if they choose other number, it will come up with error and it will just comeback to the menu that is my first problem, cant do it, second problem after creating a bank account, all the options will be enabled but they cannot create a bank account again, they should close it first, third problem if they deposit, there will be 500 minimuim deposit, and if they withdraw they cannot withdraw exceeding to that 500, i will post more organized code, i had here a algorithm for the initial deposit, but its not working


Gomez Banking Systems
////////////////////////////////////////////////////////
Step 0 : Inits (openBank = false)
////////////////////////////////////////////////////////
Step 1 : Displays 6 items, inputs (number)
////////////////////////////////////////////////////////
Step 2 : (number == 1) //Opening the bank account

Case 0 : (openBank == false) Opens the bank account, Inputs name, openBank = true goto Step 1
Case 1 : (openBank == true) Displays an error Msg, goto Step 1
////////////////////////////////////////////////////////
Step 3 : Check (number)
If (number != 1) and (openBank == false) Displays an error Msg, goto Step 1

Else Commands.... (Not given)
////////////////////////////////////////////////////////

Does this help?
Last edited on
Rebuilded program from the demonstration algorithm example :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>



void main (void) //Keep
{
bool openBank = false;
char name[32];
int c1 = 1;
int bal = 0;//balance
int c2 = 0; //additional choice
int x = 0; //(maybe) money or temp variable

while (c1 != 0)
{
clrscr();


cout<<"========================================\n";
cout<<"=Welcome to Gomez Bank=\n";
cout<<"========================================\n";
cout<<"1. Open Bank Account\n";
cout<<"2. Check Balance\n";
cout<<"3. Deposit\n";
cout<<"4. Withdraw\n";
cout<<"5. Close Bank Account\n";
cout<<"6. Exit\n";
cout<<"Please enter your transaction: ";

cin>>c1;

//////////////////////////////////////////////////////////////////////////////////
if(c1 == 1) //Step 2 : Opening bank account
/////////////////////////////////////////////////////////////////////////////////
if(openBank == false){

cout<<"\nPlease Enter Your Full Name: ";
gets(name);

cout<<"Welcome!!! The Gomez Bank account has been opened\n";
openBank = true;}
/////////////////////////////////////////////////////////////////////////////////
else cout<<"Error!!! The Gomez Bank account has already been opened\n";


//////////////////////////////////////////////////////////////////////////////////
if(c1 < 0) cout<<"Invalid choice. Please try again.\n";
//////////////////////////////////////////////////////////////////////////////////


if(c1 > 1) //Step 3 : Skip (c1 == 0) and (c1 == 1)
if(openBank == false) cout<<"Error!!! The Gomez Bank account has not been opened\n";
/////////////////////////////////////////////////////////////////////////////////
else switch (c1)  //Other commands
{

// [...] Your commands

}
//////////////////////////////////////////////////////////////////////////////////


getch();//(Does nothing) To avoid cleaning the result messages immediately
clrscr();
}



Tell us your problems with your command cases.
Last edited on
You've already posted the errors of this source? Okay, I've fixed it.
You, Turbo C++? (I'm VS, different) ? :)
Yes, i am using turbo c++, thanks again, i will wait for your reply thanks so much
Hi, i edit my code, and the errors are only 4 now, thank God

here is the code

#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>

bool openBank = false;

void main ()
{
char name[32];
int c1 = 1;
int bal = 0;//balance
int c2 = 0; //additional choice
int x = 0; //(maybe) money or temp variable

while (c1 != 0)
{
clrscr();


cout<<"========================================\n";
cout<<"=Welcome to Gomez Bank=\n";
cout<<"========================================\n";
cout<<"1. Open Bank Account\n";
cout<<"2. Check Balance\n";
cout<<"3. Deposit\n";
cout<<"4. Withdraw\n";
cout<<"5. Close Bank Account\n";
cout<<"6. Exit\n";
cout<<"Please enter your transaction: ";

cin>>c1;

//////////////////////////////////////////////////////////////////////////////////
if(c1 == 1) //Step 2 : Opening bank account
/////////////////////////////////////////////////////////////////////////////////
if(openBank == false){

cout<<"\nPlease Enter Your Full Name: ";
gets(name);

cout<<"Welcome!!! The Gomez Bank account has been opened\n";
openBank = true;}
/////////////////////////////////////////////////////////////////////////////////
else cout<<"Error!!! The Gomez Bank account has already been opened\n";


//////////////////////////////////////////////////////////////////////////////////
if(c1 < 0) cout<<"Invalid choice. Please try again.\n";
//////////////////////////////////////////////////////////////////////////////////


if(c1 > 1) //Step 3 : Skip (c1 == 0) and (c1 == 1)
if(openBank == false) cout<<"Error!!! The Gomez Bank account has not been opened\n";
/////////////////////////////////////////////////////////////////////////////////
else switch (c1) //Other commands
{

case 1:

cout<<"\nPlease Enter Your Full Name: ";
gets(name);


clrscr();
do
{
cout<<"\n\n\t\t\tNote 500 is the minimuim deposit";
cout<<"\n\nPlease Enter Your Initial Deposit: ";
cin>>x;
}while(x < 500);
bal = bal + x;


getch();
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;

if (c2 == 2)
{c1 = 0;
break;}
else if(c2 ==1){

break;
}

case 2:
cout<<"Your current balance is: "<<bal<<"\n";
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
break;


case 3:
cout<<"Enter the value you would like to deposit: ";
cin>>x;
while(x<=0)
{
cout<<"The value you've entered is invalid. \nPlease try again: ";
cin>>x;
}
bal = bal + x;
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
break;


case 4:
cout<<"Enter the value you would like to withdraw ";
cin>>x;

while (x > bal || x <=0)
{
cout<<"The value you've entered is invalid. \nPlease try again: ";
cin>>x;
}
cout<<"Would you like to do another transaction?\n";
cout<<"1.Confirm 2.Exit\n";
cout<<"Enter your choice: ";
cin>>c2;
if (c2 == 2)
{c1 = 0;}
else;
bal = bal - x;
break;


case 5:


case 6:
c1 = 0;
break;


};
}



//////////////////////////////////////////////////////////////////////////////////


getch();//(Does nothing) To avoid cleaning the result messages immediately
clrscr();
//return(0);
}




The errors are

1. Declaration syntax error
2. Undefined symbol 'open bank'
3. Undefined symbol 'false'
4. Undefined symbol 'true'

Thanks a lot for your help all the way, appreciate it
Have you reviewed and recopied the fixed source and applied it yet? I haven't seen any change from your posted source.
Maybe the global function feature is not supported.
Edit : Any another error?
Sorry, and I'll need to download and test Turbo C ++

And I'll review your code again and give you advices :)
Last edited on
Hello , good day, yes i applied everything, thank you so much, i already solved the initial deposit, the only problem that i had, is this 4 errors, the open account and the close account, That's the only problem that i had please help me,. thanks again in advanced, if you want i can send to you the software if you will give me your email address,

Hi, sorry for taking your time so much, i write a code here, yesterday, but there are some errors, i believe you are the only one who can help me


#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>
using namespace std;

double oa(double);
double dt(double);
double wt(double);
double bi(double,double,double);
double ca(double);

int main()
{

int n=0;
double x=0,y=0,z=0,p=0,i=0;
start:
system("cls");
cout <<"\t\tBANKING SYSTEM\n";
cout <<"\t[1] Open an Account\n";
cout <<"\t[2] Deposit Transaction\n";
cout <<"\t[3] Withdrawal Transaction\n";
cout <<"\t[4] Balance Inquiry\n";
cout <<"\t[5] Close Account\n";
cout <<"\t[6] Exit\n\n";
cout <<"\tPlease choose: "; cin >> n;



if(n==1)
{
if(x>0){
cout <<"\n\n\tClose the accout to create new!";
getch();
goto start;
}
x = oa(double(n));
goto start;
}
if(n==2)
{
if(x==0){
cout << "\n\n\tPlease create an account first.";
getch();
goto start;
}
if(y==0)
y = dt(x);
else
y = dt(y);
goto start;
}
if(n==3)
{
if(x==0){
cout << "\n\n\tPlease create an account first.";
getch();
goto start;
}
if(z==0)
z = wt(x);
else
z = wt(y);

goto start;
}
if(n==4)
{
if(x==0){
cout << "\n\n\tPlease create an account first.";
getch();
goto start;
}

p = bi(x,y,z);

if(p>500){
p = bi(x,y,z);
}
goto start;
}
if(n==5)
{
if(x==0){
cout << "\n\n\tPlease create an account first.";
getch();
goto start;
}
else
x = ca(x);
y = x;
z = y;
p = z;

goto start;
}
if(n==6){
system("cls");
cout <<"GOODBYE!!";
}

getch();
}



double oa(double a)
{
char b[100];
double i;
system("cls");
cout <<"Enter a name: "; cin >> b;
in:
cout <<"Enter your initial deposit (min 500): "; cin >> i;
if(i<500)
{
cout <<"The minimum is 500. Please re-enter.\n\n";
goto in;
}
cout <<"Press enter to go back to the main menu.";
getch();
return i;
}

double dt(double b)
{
double d;
system("cls");
de:
cout <<"Enter the amount to deposit (min 500): "; cin >> d;
if(d<500)
{
cout <<"You enter is below the minimun deposit. Please enter again.\n\n";
goto de;
}
b = b + d;
cout <<"Please enter to go back to the main menu. ";
cout << b;
getch();
return b;
}

double wt(double c)
{
double w,c1=0;
system("cls");
wi:
cout <<"Enter the amout to withdraw (min 500): "; cin >> w;
if(w<500){
cout <<"The minimun is 500. Please enter again.\n\n";
goto wi;
}
c1 = c - w;
if(c1<500){
cout <<"The minimun balance is 500. Please enter again.\n\n";
goto wi;
}
cout <<"Please enter to go back to the main menu. ";
getch();
return w;
}

double bi(double d,double e,double f)
{
double r;
system("cls");
if(e==0)
r = (d + e) - f;
else
r = (d + (e-d)) - f;

cout <<"Your balance is: " << r <<endl;
cout <<"Please enter to go back to the main menu. ";
getch();
return e;
}


double ca(double g)
{
bool q;
system("cls");
cout <<"Please [1] to delete Account and [0] to go back to main menu: "; cin >> q;
if(q==1){
q = 0;
cout <<"Account has been deleted.";
getch();
}
else
q = g;
return q;
}





i rather my use my old code, rather than this one,,, the only problem that i have, is the open account and close account
because the last code that i paste is not from me,, hehe, i just saw it, but same purpose
My rebuilded code :
My workspace : Verdana Font-Size : 8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>

#define OPEN 1
#define DEPOSIT 2
#define WITHDRAW 3
#define BALANCE 4
#define CLOSEACCOUNT 5
#define EXIT 6

int main()
{
//////////////////////Init
char name[64];
bool openBank = false;
double balance = 0;
double d = 0; // custom input
int choice;

bool bQuit = false;
//////////////////////Start
while(bQuit == false)
{
system("cls");

cout <<"\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n";
cout <<"\t\tBANKING SYSTEM"; if(openBank){ cout << "\tName : \"" << name << "\" Balance : " << balance; }cout <<"\n"; 
cout <<"\t[1] Open an Account\n";
cout <<"\t[2] Deposit Transaction\n";
cout <<"\t[3] Withdrawal Transaction\n";
cout <<"\t[4] Balance Inquiry\n";
cout <<"\t[5] Close Account\n";
cout <<"\t[6] Exit\n\n";
cout <<"\tPlease choose: "; cin >> choice;

cout <<"\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n";

Case :

if(choice != OPEN && openBank == false && choice !=CLOSEACCOUNT && choice != EXIT)
{cout <<"\tPlease, open the account first\n";choice = OPEN;}

//////////////////////Command
switch(choice)
{
//////////////////////////////////////////////////////////////////////////////////////////////////////
case OPEN :
	if(openBank == false){
	cout <<"\tAccount name : ";cin >> name;openBank = true;balance = 0;
	cout <<"\tWell done " << name << "! The Bank System has been opened !!!\n";
	}
	else
	{cout <<"\tYou'll need to close the account first !\n";choice = CLOSEACCOUNT;goto Case;}

break;
//////////////////////////////////////////////////////////////////////////////////////////////////////
case DEPOSIT : d = 0;
while(d < 500){
cout <<"\tEnter the amount to deposit (min 500) : "; cin >> d;if(d < 500)
cout <<"\tYou enter is below the minimum deposit. Please enter again.\n\n";}
balance = balance + d;break;
//////////////////////////////////////////////////////////////////////////////////////////////////////
case WITHDRAW : d = 501;
while(d > 500){
cout <<"\tEnter the amout to withdraw (max 500) : "; cin >> d;if(d > 500)
cout <<"\tThe maximum is 500. Please enter again.\n\n";
if(balance - d < 0) {d = 501;
cout <<"\tThe value is invalid. Please enter again\n\n";}}balance = balance - d;break;
//////////////////////////////////////////////////////////////////////////////////////////////////////
case BALANCE :
cout<<"\tYour current balance is: "<<balance<<"\n";
cout <<"Please enter to go back to the main menu. ";getch();
break;
//////////////////////////////////////////////////////////////////////////////////////////////////////
case CLOSEACCOUNT :
if(openBank == false)cout <<"The bank is closed. No need to close now.\n\n"; 
else
{
	cout <<"Please [1] to delete Account and [0] to go back to main menu: "; cin >> choice;
	if(choice == 1){name[0] = 0;openBank = false;}
}
break;
//////////////////////////////////////////////////////////////////////////////////////////////////////
case EXIT : bQuit = true; break;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////End case commands
}
//////////////////////End Bank loop
return 0;
}
//////////////////////End program... 
Last edited on
Back to your code :

Remark your new & changed code (honest) :
1- No comments (Eg : variable names too short (r,e,b, etc...), no correct meaning)
2-
cout << "\n\n\tPlease create an account first.";

Don't use too many because it's not necessary. Eg Before check a input choice :
if(choice != OPEN && openBank == false) //If your choice is not "Open bank command" but the bank hasn't opened yet

3-
double oa(double);
double dt(double);
double wt(double);
double bi(double,double,double);
double ca(double);

?!?!?!?!??!?!?!?!?!?!?!?!?!?!?!?!??!?!?!?!?!?!?!?!?!??!?!?!?!?!?!?!?!?!?!?!??!?!
Nobody knows, except you. (Add comments & parameter names)
4-
bool q; cin >> q;

"cin" command doesn't support input boolean values. Use 'int' instead.


?!?!!?!??!?!?!?!?!?!?!?!?!?!?!
-> Keep the old one is better.
(Take the code above as an example)
////////////////////////////////////////////////////////////////////////////////////////////
Any question?
Last edited on
Hi, thanks for the help, uhm i copied the rebuilded code that you pasted, thanks for the help, but i received some errors, i believe you can help me again, can you teach me how to fix these the errors only is about undefined symbol of bool, bquit, false, openbank, true, that's the only error, thanks, i am using turbo c++ is that a problem?
Hi, i just download dev c++, and it is working fine, thanks a lot, i already run your program, its working fine now, but, i have some bit problem, when i deposit some amount of money, and i withdraw, it should have a maintaining balance of 500, here in the program the maximum withdraw is 500, so its opposite , hehe, but thanks a lot for being patient and always there to help me, God Bless you and your family
Hi again, i am here again, seeking for your help, my professor told me, that i need it to do it, using functions, all of the code inside the cases needs to be in function, huhu, please help
Hi,

This should get you a long way along your road. Let me know how you get on.

Andy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <conio.h>
#include <string>
#include <map>

class CAccount;

enum OPTIONS
{
	OPEN_ACCOUNT,
	ADD_DEPOSIT,
	TAKE_WITHDRAWAL,
	BALANCE_ENQUIRY,
	CLOSE_ACCOUNT,
	EXIT
};

typedef std::map<std::string, CAccount*> ACCOUNT_TYPE;

class CAccount
{
public:
	CAccount(const std::string name)
		: m_sName(name)
		, m_fBalance(0.00)
	{
	}

	virtual ~CAccount()
	{
	}

	void add_deposit(const float amount)
	{
		m_fBalance += amount;
	}

	void make_withdrawal(const float amount)
	{
		m_fBalance -= amount;
	}

	float get_balance()
	{
		return m_fBalance;
	}

private:
	CAccount()
	{
	}

	std::string m_sName;
	float m_fBalance;
};

class CBank
{
public:
	CBank()
	{
	}

	virtual ~CBank()
	{
		for (ACCOUNT_TYPE::iterator p = m_mAccounts.begin(); p != m_mAccounts.end(); ++p)
		{
			CAccount* pAccount = p->second;
			delete pAccount;
			pAccount = NULL;
		}

		m_mAccounts.clear();
	}

	void create_new_account()
	{
		std::string name = get_account_name();

		if (!account_exists(name))
			m_mAccounts.insert(ACCOUNT_TYPE::value_type(name, new CAccount(name)));
	}

	void close_account()
	{
		const std::string name = get_account_name();

		ACCOUNT_TYPE::iterator p = m_mAccounts.find(name);
		if (p != m_mAccounts.end())
		{
			CAccount* pAccnt = p->second;
			delete pAccnt;
			pAccnt = NULL;
			m_mAccounts.erase(p);
		}
		else
		{
			// to do - account cannot be found ...
		}
	}

	void add_deposit()
	{
		const std::string name = get_account_name();

		CAccount* pAccnt = get_account(name);
		if (pAccnt)
		{
			float amount(0.00);

			// to do - get the amount of the deposit to be made

			pAccnt->add_deposit(amount);
		}
	}

	void make_withdrawal()
	{
		const std::string name = get_account_name();

		CAccount* pAccnt = get_account(name);
		if (pAccnt)
		{
			float amount(0.00);

			// to do - get the amount of the withdrawal

			pAccnt->make_withdrawal(amount);
		}
	}

	void get_balance()
	{
		const std::string name = get_account_name();

		CAccount* pAccnt = get_account(name);
		if (pAccnt)
		{
			const float amount = pAccnt->get_balance();

			// to do - tell user the balance
		}
	}

private:

	bool account_exists(const std::string& name)
	{
		return m_mAccounts.find(name) != m_mAccounts.end();
	}

	CAccount* get_account(const std::string& name)
	{
		CAccount* pAccnt = NULL;
		ACCOUNT_TYPE::iterator p = m_mAccounts.find(name);
		if (p != m_mAccounts.end())
			pAccnt = p->second;
		else
		{
			// tell user that account cannot be found
			// to do -

			_getch();
		}

		return pAccnt;
	}

	std::string get_account_name()
	{
		std::string name;
		// to do - get user to enter the name of the account

		return name;
	}

	ACCOUNT_TYPE m_mAccounts;
};

class CApp
{
public:
	CApp()
	{
	}

	virtual ~CApp()
	{
	}

	void run()
	{
		bool bRunning(true);

		while (bRunning)
		{
			OPTIONS choice = show_main_menu();
		
			switch(choice)
			{
				case OPEN_ACCOUNT:
					m_the_bank.create_new_account();
					break;
				case ADD_DEPOSIT:
					m_the_bank.add_deposit();
					break;
				case TAKE_WITHDRAWAL:
					m_the_bank.make_withdrawal();
					break;
				case BALANCE_ENQUIRY:
					m_the_bank.get_balance();
					break;
				case CLOSE_ACCOUNT:
					m_the_bank.close_account();
					break;
				case EXIT:
					// to do - show goodbye etc...
					bRunning = false;
					break;
			};
		}
	}

private:
	OPTIONS show_main_menu()
	{
		OPTIONS choice(OPEN_ACCOUNT);
		// to do 


		return choice;
	}

	CBank m_the_bank;
};

int main(int argc, char* argv[])
{
	CApp the_app;
	the_app.run();
	return 0;
}
Pages: 12