-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdated_code_with_menu_System.cpp
More file actions
104 lines (82 loc) · 2.33 KB
/
updated_code_with_menu_System.cpp
File metadata and controls
104 lines (82 loc) · 2.33 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
#include <iostream>
#include <string>
using namespace std;
class BankAccount {
private:
string name;
int accountNumber;
double balance;
public:
void createAccount() {
cout << "Enter your name: ";
getline(cin, name);
cout << "Enter your account number: ";
cin >> accountNumber;
balance = 0.0;
cin.ignore();
cout << "Account created successfully!" << endl;
}
void showAccount() const {
cout << "\nAccount Details:" << endl;
cout << "Name: " << name << endl;
cout << "Account Number: " << accountNumber << endl;
cout << "Balance: " << balance << endl;
}
void deposit(double amount) {
if (amount > 0) {
balance += amount;
cout << "Deposited: " << amount << endl;
cout << "New balance: " << balance << endl;
} else {
cout << "Invalid deposit amount!" << endl;
}
}
void withdraw(double amount) {
if (amount > 0) {
if (amount <= balance) {
balance -= amount;
cout << "Withdrawn: " << amount << endl;
cout << "Remaining balance: " << balance << endl;
} else {
cout << "Insufficient balance!" << endl;
}
} else {
cout << "Invalid withdraw amount!" << endl;
}
}
};
int main() {
BankAccount myAccount;
myAccount.createAccount();
int choice;
int amount;
do{
cout<<"<------Banking Menu------>"<<endl;
cout<<"1. Deposit Money"<<endl;
cout<<"2. Withdraw Money"<<endl;
cout<<"3. Show Account Details"<<endl;
cout<<"4. Exit"<<endl;
cin>>choice;
switch(choice){
case 1:
cout<<"Enter The Amount: "<<endl;
cin>>amount;
myAccount.deposit(amount);
break;
case 2:
cout<<"Enter The Amount: "<<endl;
cin>>amount;
myAccount.withdraw(amount);
break;
case 3:
myAccount.showAccount();
break;
case 4:
cout<<"Exited Program, Have A Good Day!!"<<endl;
break;
default:
cout<<"invalid choice. Choose Again"<<endl;
}
}while(choice!=4);
return 0;
}