Simple Banking Program using C++
Simple Banking Program using C++
Today I am going to write a solution for simple banking program in C++. The program uses Classes and objects. Coming to the explanation of the program:
#1. We first defined a class called Bank.
#2. In the class we have defined ac – Account Number as int (integer), reset is defined for Checking balance and float Balance, amount are used for calculating Deposits and Withdrawls. Shorta variable is used for calculating Withdrawl limit.
#3. If you define a static variable inside a class, you must define it outside of class using the format
#4. We are using a single account number (Here we are using a account number: 1001) here, But we’ll write another program that will use an array with a list of Account Numbers.
#5. If you want to deposit money, You need to enter the account number and amount you would like to deposit, We have used reset++ in the Deposit because it is used for
#6. If you would like to withdraw money, You need to enter the account number and amount you would like to withdraw. Here comes the use of our variable
#7. We are using reset variable for the purpose of clearing any garbage value in Balance variable. If the user checks for Balance without any deposit in the account, he may get some garbage valued output. So if he has deposited some money into the account, reset will be incremented leaving the balance variable intact.
#2. In the class we have defined ac – Account Number as int (integer), reset is defined for Checking balance and float Balance, amount are used for calculating Deposits and Withdrawls. Shorta variable is used for calculating Withdrawl limit.
#3. If you define a static variable inside a class, you must define it outside of class using the format
dataype classname::staticvariable-name;
. Where :: is scope resolution operator.#4. We are using a single account number (Here we are using a account number: 1001) here, But we’ll write another program that will use an array with a list of Account Numbers.
#5. If you want to deposit money, You need to enter the account number and amount you would like to deposit, We have used reset++ in the Deposit because it is used for
chkbalance()
function.#6. If you would like to withdraw money, You need to enter the account number and amount you would like to withdraw. Here comes the use of our variable
shorta
. Using an if condition, if the amount entered is greater than the account balance then it will throw an error that Your account is short of some x money.#7. We are using reset variable for the purpose of clearing any garbage value in Balance variable. If the user checks for Balance without any deposit in the account, he may get some garbage valued output. So if he has deposited some money into the account, reset will be incremented leaving the balance variable intact.
Banking Program in C++
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
| /* Simple Banking Program using C++ */ #include< iostream.h > #include< conio.h > #include< stdlib.h > class bank { int ac; static reset; float balance, amount, shorta; public: void deposit(); void withdraw(); void chkbalance(); int menu(); }; int bank::reset=0; void bank::deposit() { cout<<"\nEnter Account Number:"; cin>>ac; if(ac==1001) { cout<<"\nEnter Amount you want to Deposit:"; cin>>amount; balance=balance+amount; cout<<"\n\nMessage: You have successfully deposited Rs."<< amount <<" into your account.\n\nYour Current Balance is:"<<balance<<"\n\n"; reset++; } else { cout<<"You have entered invalid account number"; } } void bank::withdraw() { cout<<"Enter Account Number:"; cin>>ac; if(ac==1001) { cout<<"Enter Amount you want to Withdraw:"; cin>>amount; if(amount>balance) { shorta=amount-balance; cout<<"\n\nYou cannot withdraw Rs."<< amount <<" as your account balance is Rs."<<balance<<"\n\nYou are short of Rs."<<shorta; } else { balance =balance-amount; cout<<"You have Withdrawn Rs."<<amount<<" Successfully\n\n Your account balance is:"<<balance<<"\n\n"; } } else { cout<<"You have entered invalid account number"; } } void bank::chkbalance() { cout<<"Enter Account Number:"; cin>>ac; if(reset==0) { balance=0; } if(ac==1001) { cout<<"Your Account balance is Rs."<< balance <<"\n\n"; } else { cout<<"Account Doesn't Exist!!"; } } void main() { bank ob; int ch; clrscr(); do { cout<<"\n\n\n1.Deposit\n2.Withdraw\n3.Balance Enquiry\n4.Exit\n\n"; ch = ob .menu(); switch(ch) { case 1:ob.deposit(); break; case 2:ob.withdraw(); break; case 3:ob.chkbalance(); break; case 4: exit(1); default:cout<<"Invalid Choice!!"; } }while(1); } int bank::menu() { int ch; cout<<"\nEnter your Choice:"; cin>>ch; return ch; } |
Output:
0 comments:
Post a Comment