Skip to content

Banking management with login page.cpp  #4

Open
@kuldeepRathod9136

Description

@kuldeepRathod9136

#include
#include
#include
#include
using namespace std;

// User Login
bool login() {
string username, password;
cout << "=== Bank Management System Login ===\n";
cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
cin >> password;

// Simple hardcoded credentials (replace with file/db in real use)
if (username == "admin" && password == "1234") {
    cout << "Login successful!\n\n";
    return true;
} else {
    cout << "Invalid credentials!\n";
    return false;
}

}

class Account {
public:
int accNo,aadharNo,accountHolder,accountNumber;
string name;
float balance;

void createAccount() {
    cout << "Enter last three digit aadhar Number: ";
    cin >> aadharNo;
    cout << "Enter Name: ";
    cin.ignore();
    getline(cin, name);
    cout << "Enter Initial Balance: ";
    cin >> balance;

    ofstream outFile("accounts.txt", ios::app);
    outFile << accNo << " " << name << " " << balance << endl;
    outFile.close();

    cout << "Account created successfully!\n";
}

void viewAccounts() {
    ifstream inFile("accounts.txt");
    cout << left << setw(10) << "Acc No" << setw(20) << "Name" << setw(10) << "Balance" << endl;
    cout << "-------------------------------------------\n";

    while (inFile >> accNo) {
        inFile.ignore();
        getline(inFile, name, ' ');
        inFile >> balance;
        cout << left << setw(10) << accNo << setw(20) << name << setw(10) << balance << endl;
    }

    inFile.close();
}

void depositOrWithdraw(bool isDeposit) {
    int searchAcc;
    float amount;
    cout << "Enter Account Number: ";
    cin >> searchAcc;
    cout << "Enter Amount: ";
    cin >> amount;

    ifstream inFile("accounts.txt");
    ofstream tempFile("temp.txt");

    bool found = false;
    while (inFile >> accNo) {
        inFile.ignore();
        getline(inFile, name, ' ');
        inFile >> balance;

        if (accNo == searchAcc) {
            found = true;
            if (isDeposit)
                balance += amount;
            else {
                if (balance >= amount)
                    balance -= amount;
                else {
                    cout << "Insufficient balance!\n";
                    tempFile << accNo << " " << name << " " << balance << endl;
                    continue;
                }
            }
            cout << "Transaction successful!\n";
        }
        tempFile << accNo << " " << name << " " << balance << endl;
    }

    inFile.close();
    tempFile.close();
    remove("accounts.txt");
    rename("temp.txt", "accounts.txt");

    if (!found) {
        cout << "Account not found!\n";
    }
}

void display() {
cout << "\nAccount Holder: " << accountHolder << endl;
cout << "Account Number: " << accountNumber << endl;
cout << "Balance: $" << balance << endl;
}
};

int main() {
if (!login()) return 0;

Account acc;
int choice;

do {
    cout << "\n===== Bank Menu =====\n";
    cout << "1. Create Account\n";
    cout << "2. View All Accounts\n";
    cout << "3. Deposit\n";
    cout << "4. Withdraw\n";
    cout << "5. display\n";
    cout << "6. Exit\n";
    cout << "Choose an option: ";
    cin >> choice;

    switch (choice) {
        case 1:
            acc.createAccount();
            break;
        case 2:
            acc.viewAccounts();
            break;
        case 3:
            acc.depositOrWithdraw(true);
            break;
        case 4:
            acc.depositOrWithdraw(false);
            break;
        case 5 :
             acc.display();
        case 6:
            cout << "Exiting...\n";
            break;
        default:
            cout << "Invalid choice!\n";
            break;
    }
} while (choice != 6);

return 0;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions