Bank Management System Project in c++ (Using Functions)

Table of Contents

Source Code

#include <iostream>
#include <string>

struct BankAccount
{
    int accountNumber;
    std::string accountHolder;
    double balance;
};

void createAccount(BankAccount &account, int accountNumber, std::string accountHolder, double balance)
{
    account.accountNumber = accountNumber;
    account.accountHolder = accountHolder;
    account.balance = balance;
}

void deposit(BankAccount &account, double amount)
{
    account.balance += amount;
}

void withdraw(BankAccount &account, double amount)
{
    if (amount > account.balance)
        std::cout << "Insufficient funds." << std::endl;
    else
        account.balance -= amount;
}

int main()
{
    BankAccount account;
    createAccount(account, 123456, "John Smith", 1000);
    std::cout << "Account Number: " << account.accountNumber << std::endl;
    std::cout << "Account Holder: " << account.accountHolder << std::endl;
    std::cout << "Balance: $" << account.balance << std::endl;

    deposit(account, 500);
    std::cout << "Balance after deposit: $" << account.balance << std::endl;

    withdraw(account, 2000);
    std::cout << "Balance after withdraw: $" << account.balance << std::endl;

    return 0;
}

Code Explanation

This is a basic example of how you can use functions to create a bank account management system in C++. This example uses a BankAccount struct to store the account information, and three functions: createAccount(), deposit(), and withdraw().

In the main() function, an instance of the BankAccount struct is created with the help of the createAccount() function, account number, account holder name, and initial balance are passed as arguments. The account number, account holder name, and balance are displayed, and the deposit and withdraw functions are tested.

This is a simple program and you can improve it by adding more functionality like account creation, account deletion, passbook printing, statement generation, and many more.

Please note that this is a simple example and is not meant for any real use. It does not include security measures and error checking that would be needed for a real-world application.

C++ Examples with Solution