C++ Bank Management System
#include<iostream>
using namespace std;
class ourbank {
int accN;
float balance;
int totalTransaction = 0;
int password = 0;
int failedAttempts = 0;
bool isLocked = false;
string phoneNumber;
public:
void setData(int n, float b, int p, string phone) {
accN = n;
balance = b;
password = p;
phoneNumber = phone;
failedAttempts = 0;
isLocked = false;
}
float getBalance() {
return balance;
}
bool setBalance(float b) {
if (balance + b < 0) return false;
balance += b;
return true;
}
void setTransaction() {
totalTransaction++;
}
int getTransaction() {
return totalTransaction;
}
bool login(int acc, int pin) {
if (isLocked) return false;
if (acc == accN && pin == password) {
failedAttempts = 0;
return true;
} else {
failedAttempts++;
if (failedAttempts >= 3) {
isLocked = true;
}
return false;
}
}
bool getLockStatus() {
return isLocked;
}
};
ourbank bank[1000];
int total = 0;
void create() {
float initialAmount;
int pin;
string phone;
cout << "Account Creation\n";
cout << "Your new account number is: " << total + 1 << endl;
while (true) {
cout << "Enter your phone number (11 digits): ";
cin >> phone;
if (phone.length() == 11) {
bool allDigits = true;
for (char c : phone) {
if (!isdigit(c)) {
allDigits = false;
break;
}
}
if (allDigits) break;
else cout << "Phone number must contain only digits.\n";
} else {
cout << "Phone number must be exactly 11 digits long.\n";
}
}
cout << "Create a 6-digit PIN: ";
cin >> pin;
cout << "Enter initial deposit amount: ";
cin >> initialAmount;
bank[total].setData(total + 1, initialAmount, pin, phone);
bank[total].setTransaction();
total++;
cout << "Account creation successful.\n";
}
bool validateLogin(int acc, int& index, int pin) {
if (acc <= 0 || acc > total) return false;
index = acc - 1;
if (bank[index].getLockStatus()) {
cout << "Account is locked due to 3 failed login attempts.\n";
return false;
}
if (!bank[index].login(acc, pin)) {
if (bank[index].getLockStatus())
cout << "Incorrect PIN. Your account is now locked.\n";
else
cout << "Incorrect PIN.\n";
return false;
}
return true;
}
// Other functions truncated for brevity in this sample
int main() {
int option;
while (true) {
cout << "\n MENU\n";
cout << "1. Create account\n";
cout << "2. Withdraw\n";
cout << "3. Deposit\n";
cout << "4. Fund transfer\n";
cout << "5. Show balance\n";
cout << "6. Pay bill\n";
cout << "7. Total transactions\n";
cout << "8. Exit\n";
cout << "Select option: ";
cin >> option;
if (option == 8) break;
switch (option) {
case 1: create(); break;
case 2: withdrawl(); break;
case 3: deposit(); break;
case 4: transfer(); break;
case 5: showBalance(); break;
case 6: paybill(); break;
case 7: transaction(); break;
default: cout << "Invalid option.\n";
}
}
return 0;
}
Sample Terminal Output
MENU
1. Create account
2. Withdraw
3. Deposit
4. Fund transfer
5. Show balance
6. Pay bill
7. Total transactions
8. Exit
Select option: 1
Account Creation
Your new account number is: 1
Enter your phone number (11 digits): 01712345678
Create a 6-digit PIN: 123456
Enter initial deposit amount: 10000
Account creation successful.
MENU
Select option: 3
Enter your account number: 1
Enter your PIN: 123456
Deposit amount: 2000
MENU
Select option: 5
Enter your account number: 1
Enter your PIN: 123456
Account balance: 12000
MENU
Select option: 2
Your account No.: 1
Enter your PIN: 123456
Withdrawal amount: 5000
Available balance: 7000
MENU
Select option: 6
Enter your account number: 1
Enter your PIN: 123456
Bill amount: 1000
1% processing fee will be charged. Confirm with 1: 1
Payment successful. Remaining balance: 5990
MENU
Select option: 7
Enter your account number: 1
Enter your PIN: 123456
Total transactions: 4
MENU
Select option: 8