This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathOnline_Banking.cpp
92 lines (82 loc) · 3.05 KB
/
Online_Banking.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
#include <iostream>
#include <map>
class Bank {
private:
std::map<int, double> accounts; // Map account numbers to balances
int nextAccountNumber;
public:
Bank() : nextAccountNumber(1) {}
int createAccount() {
accounts[nextAccountNumber] = 0.0;
return nextAccountNumber++;
}
void deposit(int accountNumber, double amount) {
if (accounts.find(accountNumber) != accounts.end()) {
accounts[accountNumber] += amount;
std::cout << "Deposited $" << amount << " into account " << accountNumber << std::endl;
} else {
std::cout << "Account not found." << std::endl;
}
}
void withdraw(int accountNumber, double amount) {
if (accounts.find(accountNumber) != accounts.end()) {
if (accounts[accountNumber] >= amount) {
accounts[accountNumber] -= amount;
std::cout << "Withdrew $" << amount << " from account " << accountNumber << std::endl;
} else {
std::cout << "Insufficient balance." << std::endl;
}
} else {
std::cout << "Account not found." << std::endl;
}
}
void checkBalance(int accountNumber) {
if (accounts.find(accountNumber) != accounts.end()) {
std::cout << "Account " << accountNumber << " has a balance of $" << accounts[accountNumber] << std::endl;
} else {
std::cout << "Account not found." << std::endl;
}
}
};
int main() {
Bank bank;
int choice, accountNumber;
double amount;
while (true) {
std::cout << "Banking System Menu:" << std::endl;
std::cout << "1. Create Account" << std::endl;
std::cout << "2. Deposit" << std::endl;
std::cout << "3. Withdraw" << std::endl;
std::cout << "4. Check Balance" << std::endl;
std::cout << "5. Exit" << std::endl;
std::cout << "Enter your choice: ";
std::cin >> choice;
switch (choice) {
case 1:
accountNumber = bank.createAccount();
std::cout << "Account created with number " << accountNumber << std::endl;
break;
case 2:
std::cout << "Enter account number and amount to deposit: ";
std::cin >> accountNumber >> amount;
bank.deposit(accountNumber, amount);
break;
case 3:
std::cout << "Enter account number and amount to withdraw: ";
std::cin >> accountNumber >> amount;
bank.withdraw(accountNumber, amount);
break;
case 4:
std::cout << "Enter account number to check balance: ";
std::cin >> accountNumber;
bank.checkBalance(accountNumber);
break;
case 5:
std::cout << "Exiting the banking system. Goodbye!" << std::endl;
return 0;
default:
std::cout << "Invalid choice. Please try again." << std::endl;
}
}
return 0;
}