-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.Bank account.cpp
102 lines (95 loc) · 2.81 KB
/
01.Bank account.cpp
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
using namespace std;
#include<iostream>
class Bank {
public:
int accNo;
string accHolder;
double balance;
public:
Bank(string name = "no name", int no = 0, double amt = 0) {
accHolder = name;
accNo = no;
balance = amt;
}
void create(int);
void deposit();
void withdraw();
void display();
};
void Bank::create(int a) {
accNo = a;
cout << " Enter account holder name : ";
cin >> accHolder;
cout << " Congratulations " << accHolder << "!" << endl;
cout << " Your account has been successfully created!" << endl;
cout << " Your account number is " << accNo << "." << endl;
cout << " Kindly remember it for future reference.\n";
}
void Bank::deposit() {
cout << " Enter amount to be deposited : ";
double amt;
cin >> amt;
balance+= amt;
cout << " Rs. " << amt << " has been deposited on account number " << accNo << ".\nThank you.\n";
}
void Bank::withdraw() {
cout << " Enter amount to be withdrawn : ";
double amt;
cin >> amt;
balance-= amt;
cout << " Rs. " << amt << " has been withdrawn from account number " << accNo << ".\nThank you.\n";
}
void Bank::display() {
cout << " Account holder name : " << accHolder << endl;
cout << " Account number : " << accNo << endl;
cout << " Account balance : " << balance << endl;
}
int main() {
int choice, n, i, x;
i = 0;
cout << "Maximum number of accounts : ";
cin >> n;
Bank b[n];
while (1) {
cout << "\n\nMENU\nPress 1 to create account.\nPress 2 to deposit.\nPress 3 to withdraw.\nPress 4 to display account details.\nPress 5 to exit.\n";
cout << "Enter your choice : ";
cin >> choice;
switch(choice) {
case 1:
b[i].create(i+1);
i++;
break;
case 2:
cout << " Enter account number : ";
cin >> x;
if (b[x-1].accNo == 0) {
cout << " Account doesn't exist.\n";
break;
}
b[x-1].deposit();
break;
case 3:
cout << "E nter account number : ";
cin >> x;
if (b[x-1].accNo == 0) {
cout << " Account doesn't exist.\n";
break;
}
b[x-1].withdraw();
break;
case 4:
cout << " Enter account number : ";
cin >> x;
if (b[x-1].accNo == 0) {
cout << " Account doesn't exist.\n";
break;
}
b[x-1].display();
break;
default:
exit(0);
break;
}
}
return 0;
}