-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank_system.cpp
More file actions
190 lines (161 loc) · 5.07 KB
/
Copy pathbank_system.cpp
File metadata and controls
190 lines (161 loc) · 5.07 KB
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
#include <iostream>
#include <string>
using namespace std;
struct Customer {
string name;
int accNo;
};
class BankAccount {
private:
Customer cust;
float balance;
static int totalAccounts;
static float totalBankBalance;
public:
BankAccount() {
cust.name = "N/A";
cust.accNo = 0;
balance = 0.0;
}
void createAccount(const string& n, int a, float b) {
cust.name = n;
cust.accNo = a;
balance = b;
totalAccounts++;
totalBankBalance += b;
}
void deposit(float amount) {
if (amount > 0) {
balance += amount;
totalBankBalance += amount;
cout << "Deposited Rs." << amount << " successfully.\n";
} else {
cout << "Invalid amount!\n";
}
}
void withdraw(float amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
totalBankBalance -= amount;
cout << "Withdrawn Rs." << amount << " successfully.\n";
} else {
cout << "Insufficient balance or invalid amount!\n";
}
}
void displayDetails() const {
cout << "\n--- Account Details ---\n";
cout << "Account Holder: " << cust.name << endl;
cout << "Account Number: " << cust.accNo << endl;
cout << "Current Balance: Rs." << balance << endl;
}
int getAccountNo() const {
return cust.accNo;
}
static void showBankSummary() {
cout << "\n--- Bank Summary ---";
cout << "\nTotal Accounts: " << totalAccounts;
cout << "\nTotal Balance in Bank: Rs." << totalBankBalance << endl;
}
};
int BankAccount::totalAccounts = 0;
float BankAccount::totalBankBalance = 0.0;
int main() {
const int MAX = 5;
BankAccount accounts[MAX];
int accountCount = 0;
int choice;
cout << "===============================\n";
cout << " BANK MANAGEMENT SYSTEM\n";
cout << "===============================\n";
do {
cout << "\n--- MAIN MENU ---\n";
cout << "1. Create New Account\n";
cout << "2. Deposit Money\n";
cout << "3. Withdraw Money\n";
cout << "4. Display Account Details\n";
cout << "5. Show Bank Summary\n";
cout << "6. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
if (choice == 1) {
if (accountCount < MAX) {
string name;
int accNo;
float initialBalance;
cin.ignore();
cout << "\nEnter Customer Name: ";
getline(cin, name);
cout << "Enter Account Number: ";
cin >> accNo;
cout << "Enter Initial Deposit: Rs.";
cin >> initialBalance;
accounts[accountCount].createAccount(name, accNo, initialBalance);
accountCount++;
cout << "Account created successfully!\n";
} else {
cout << "Cannot create more accounts (limit reached)!\n";
}
}
else if (choice == 2) {
int accNo;
float amount;
cout << "\nEnter Account Number: ";
cin >> accNo;
bool found = false;
for (int i = 0; i < accountCount; i++) {
if (accounts[i].getAccountNo() == accNo) {
cout << "Enter amount to deposit: Rs.";
cin >> amount;
accounts[i].deposit(amount);
found = true;
break;
}
}
if (!found)
cout << "Account not found!\n";
}
else if (choice == 3) {
int accNo;
float amount;
cout << "\nEnter Account Number: ";
cin >> accNo;
bool found = false;
for (int i = 0; i < accountCount; i++) {
if (accounts[i].getAccountNo() == accNo) {
cout << "Enter amount to withdraw: Rs.";
cin >> amount;
accounts[i].withdraw(amount);
found = true;
break;
}
}
if (!found)
cout << "Account not found!\n";
}
else if (choice == 4) {
int accNo;
cout << "\nEnter Account Number: ";
cin >> accNo;
bool found = false;
for (int i = 0; i < accountCount; i++) {
if (accounts[i].getAccountNo() == accNo) {
accounts[i].displayDetails();
found = true;
break;
}
}
if (!found)
cout << "Account not found!\n";
}
else if (choice == 5) {
BankAccount::showBankSummary();
}
else if (choice == 6) {
cout << "\nThank you for using Bank Management System!\n";
}
else {
cout << "Invalid choice! Please try again.\n";
}
} while (choice != 6);
return 0;
}