-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.cpp
More file actions
213 lines (185 loc) · 5.51 KB
/
bank.cpp
File metadata and controls
213 lines (185 loc) · 5.51 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class account {
private:
string name;
static int accno_counter;
int accno;
string phone;
float balance;
int pin;
public:
account() {}
account(int a, string n, string ph, int p, float b) {
accno = a;
name = n;
phone = ph;
pin = p;
balance = b;
}
void makeaccount(vector<account>& accounts) {
accno_counter++;
accno = accno_counter;
cout << "enter accountholder name :\n";
cin >> name;
cout << "enter your phone number (10 digits):\n";
cin >> phone;
if(phone.length() != 10 || phone.find_first_not_of("0123456789") != string::npos) {
cout << "not a valid phone number\n";
return;
}
cout << "phone number is : " << phone << "\n";
cout << "enter a 4-digit pin: \n";
cin >> pin;
if(pin<1000 || pin>9999) {
cout << "invalid pin... \n";
return;
}
int againpin;
cout << "enter pin again to confirm: \n";
cin >> againpin;
if(againpin != pin) {
cout << "pins do not match...\n";
return;
} else {
cout << "your pin is saved\n";
}
cout << "enter initial balance:\n";
cin >> balance;
if(balance<0) {
cout << "invalid balance\n";
return;
}
cout << "account created successfully\n";
cout << "your account number is : " << accno << "\n";
accounts.push_back(*this);
}
void withdraw(vector<account>& accounts) {
cout << "enter amount:\n";
float amount;
cin >> amount;
if(amount>0 && amount<balance) {
balance -= amount;
cout << "now your balance is after withdrew :\n" << balance;
cout << "successfully done\n";
} else {
cout << "enter a valid amount\n";
}
accounts.push_back(*this);
}
void deposit(vector<account>& accounts) {
cout << "enter amount:"<<"\n";
float amount;
cin >> amount;
if(amount>0) {
balance += amount;
cout << "successfully done deposit \n";
cout << "now your balance is :" << balance<<"\n";
} else {
cout << "enter a valid amount\n";
}
}
void display(vector<account>& accounts) {
cout << "account holder name: " << name << "\n";
cout << "account number: " << accno << "\n";
cout << "your current balance is: " << balance << "\n";
cout << "phone number: " << phone << "\n";
cout << "pin: " << pin << "\n";
}
void transfer(vector<account>& accounts) {
cout << "enter amount to transfer:\n";
float amount;
cin >> amount;
cout << "enter account number to transfer to:\n";
int to_accno;
cin >> to_accno;
account* to_account = nullptr;
for (auto& acc : accounts) {
if (acc.accno == to_accno) {
to_account = &acc;
break;
}
}
if (!to_account) {
cout << "Destination account not found.\n";
return;
}
if (amount > 0 && amount < balance) {
balance -= amount;
to_account->balance += amount;
cout << "Successfully transferred\n";
} else {
cout << "Enter a valid amount\n";
}
}
void deleteaccount(vector<account>& accounts){
cout<<"HAHAHA ABHI BAKI HAII ";
//cout << "Account not found or already deleted\n";
}
friend account* verifyuser(vector<account>& accounts);
};
account* verifyuser(vector<account>& accounts) {
cout << "enter account number:\n";
int acc_no;
cin >> acc_no;
cout << "enter pin:\n";
int p;
cin >> p;
for (auto &acc : accounts) {
if (acc.accno == acc_no && acc.pin == p) {
cout << "User verified!\n";
return &acc;
}
}
cout << "Invalid account number or pin.\n";
return nullptr;
}
int account::accno_counter = 0;
vector<account> accounts;
int main() {
//accounts.push_back(account(101, "disha", "9876543210", 1234, 5000));
// accounts.push_back(account(102, "dish", "1234567890", 5678, 3000));
do{
cout << " 1 : make new account \n";
cout << " 2 : withdraw amount \n";
cout << " 3 : deposit amount \n";
cout << "4 : trensfer amount \n";
cout << "5 : delete account \n";
cout << "6 : display account details \n";
int choice;
cin >> choice;
if(choice == 1) {
account a1;
a1.makeaccount(accounts);
} else if(choice == 2) {
account* user = verifyuser(accounts);
if(user) {
user->withdraw(accounts);
}
}else if(choice==3){
account* user= verifyuser(accounts);
if(user){
user->deposit(accounts);
}
}else if(choice==4){
account* user = verifyuser(accounts);
if(user){
user->transfer(accounts);
}
}else if(choice==5){
account* user= verifyuser(accounts);
if(user){
user->deleteaccount(accounts);
}
}else if(choice==6){
account* user= verifyuser(accounts);
if(user){
user->display(accounts);
}
}else {
cout<<"exit\n";
} } while(true);
return 0;
}