-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank_Management.cpp
More file actions
226 lines (197 loc) · 6.45 KB
/
Bank_Management.cpp
File metadata and controls
226 lines (197 loc) · 6.45 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
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
#include <bits/stdc++.h>
using namespace std;
// Transaction class
class Transaction {
public:
string type; // Deposit, Withdrawal, Transfer
double amount;
string date;
Transaction(string t, double amt) {
type = t;
amount = amt;
// Get current date/time
time_t now = time(0);
date = ctime(&now);
date.pop_back(); // remove newline
}
void displayTransaction() {
cout << date << " | " << type << " | Amount: $" << amount << endl;
}
};
// Account class
class Account {
private:
int accountNumber;
double balance;
vector<Transaction> transactions;
public:
Account(int accNo) {
accountNumber = accNo;
balance = 0.0;
}
int getAccountNumber() {
return accountNumber;
}
double getBalance() {
return balance;
}
void deposit(double amount) {
balance += amount;
transactions.push_back(Transaction("Deposit", amount));
cout << "Deposit successful. New balance: $" << balance << endl;
}
void withdraw(double amount) {
if (amount <= balance) {
balance -= amount;
transactions.push_back(Transaction("Withdrawal", amount));
cout << "Withdrawal successful. New balance: $" << balance << endl;
} else {
cout << "Insufficient balance!" << endl;
}
}
void transfer(Account &receiver, double amount) {
if (amount <= balance) {
balance -= amount;
receiver.balance += amount;
transactions.push_back(Transaction("Transfer Sent", amount));
receiver.transactions.push_back(Transaction("Transfer Received", amount));
cout << "Transfer successful. Your new balance: $" << balance << endl;
} else {
cout << "Insufficient balance for transfer!" << endl;
}
}
void displayAccountInfo() {
cout << "Account Number: " << accountNumber << endl;
cout << "Current Balance: $" << balance << endl;
cout << "Transaction History:" << endl;
if (transactions.empty()) {
cout << "No transactions yet." << endl;
} else {
for (auto &t : transactions) {
t.displayTransaction();
}
}
}
};
// Customer class
class Customer {
private:
string name;
int customerID;
Account account;
public:
Customer(string n, int id, int accNo) : account(accNo) {
name = n;
customerID = id;
}
int getCustomerID() {
return customerID;
}
Account& getAccount() {
return account;
}
void displayCustomerInfo() {
cout << "\n--- Customer Information ---" << endl;
cout << "Customer Name: " << name << endl;
cout << "Customer ID: " << customerID << endl;
account.displayAccountInfo();
}
};
// Find customer by ID
Customer* findCustomerByID(vector<Customer> &customers, int id) {
for (auto &c : customers) {
if (c.getCustomerID() == id) {
return &c;
}
}
return nullptr;
}
// Main Program
int main() {
vector<Customer> customers;
int choice, customerID, accountNumber;
string name;
cout << "=== Welcome to Simple Banking System ===" << endl;
do {
cout << "\nMenu:\n";
cout << "1. Create New Customer\n";
cout << "2. Deposit Money\n";
cout << "3. Withdraw Money\n";
cout << "4. Transfer Funds\n";
cout << "5. View Account Information\n";
cout << "6. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter Customer Name: ";
cin.ignore();
getline(cin, name);
cout << "Enter Customer ID: ";
cin >> customerID;
cout << "Enter Account Number: ";
cin >> accountNumber;
customers.push_back(Customer(name, customerID, accountNumber));
cout << "Customer account created successfully!\n";
break;
case 2:
cout << "Enter Customer ID for Deposit: ";
cin >> customerID;
if (Customer *cust = findCustomerByID(customers, customerID)) {
double amt;
cout << "Enter amount to deposit: ";
cin >> amt;
cust->getAccount().deposit(amt);
} else {
cout << "Customer not found!" << endl;
}
break;
case 3:
cout << "Enter Customer ID for Withdrawal: ";
cin >> customerID;
if (Customer *cust = findCustomerByID(customers, customerID)) {
double amt;
cout << "Enter amount to withdraw: ";
cin >> amt;
cust->getAccount().withdraw(amt);
} else {
cout << "Customer not found!" << endl;
}
break;
case 4:
int receiverID;
cout << "Enter Sender Customer ID: ";
cin >> customerID;
cout << "Enter Receiver Customer ID: ";
cin >> receiverID;
if (Customer *sender = findCustomerByID(customers, customerID)) {
if (Customer *receiver = findCustomerByID(customers, receiverID)) {
double amt;
cout << "Enter amount to transfer: ";
cin >> amt;
sender->getAccount().transfer(receiver->getAccount(), amt);
} else {
cout << "Receiver not found!" << endl;
}
} else {
cout << "Sender not found!" << endl;
}
break;
case 5:
cout << "Enter Customer ID to view info: ";
cin >> customerID;
if (Customer *cust = findCustomerByID(customers, customerID)) {
cust->displayCustomerInfo();
} else {
cout << "Customer not found!" << endl;
}
break;
case 6:
cout << "Exiting... Thank you for using our system!" << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 6);
return 0;
}