-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.cpp
More file actions
81 lines (79 loc) · 1.7 KB
/
Copy pathbank.cpp
File metadata and controls
81 lines (79 loc) · 1.7 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
#include <iostream>
#include <string>
using namespace std;
class BankAccount {
private:
int accountNumber;
string name;
float balance;
public:
void createAccount() {
cout << "Enter Account Number: ";
cin >> accountNumber;
cin.ignore();
cout << "Enter Account Holder Name: ";
getline(cin, name);
cout << "Enter Initial Balance: ?";
cin >> balance;
cout << "\nAccount Created Successfully!\n";
}
void deposit() {
float amount;
cout << "Enter amount to deposit: ?";
cin >> amount;
if (amount > 0) {
balance += amount;
cout << "?" << amount << " deposited successfully.\n";
} else {
cout << "Invalid deposit amount.\n";
}
}
void withdraw() {
float amount;
cout << "Enter amount to withdraw: ?";
cin >> amount;
if (amount > 0 && amount <= balance) {
balance -= amount;
cout << "?" << amount << " withdrawn successfully.\n";
} else {
cout << "Insufficient balance or invalid amount.\n";
}
}
void displayBalance() const {
cout << "\n--- Account Details ---\n";
cout << "Account Number : " << accountNumber << endl;
cout << "Account Holder : " << name << endl;
cout << "Current Balance : ?" << balance << endl;
}
};
int main() {
BankAccount myAccount;
int choice;
myAccount.createAccount();
do {
cout << "\n--- Bank Menu ---\n";
cout << "1. Deposit\n";
cout << "2. Withdraw\n";
cout << "3. Display Balance\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
myAccount.deposit();
break;
case 2:
myAccount.withdraw();
break;
case 3:
myAccount.displayBalance();
break;
case 4:
cout << "Thank you for using our banking system.\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
}
} while (choice != 4);
return 0;
}