Bank Management System using C++

Bank Management System using C++ (With Source Code)

Bank Management System using C++ (With Source Code)

Hello, coders. Welcome to the codewithrandom blog. In this article, we will learn how to create a Bank Management System using C++ (With Source Code).

A Bank Management System is a console based application which is used to manage bank account records. The system allows the user to add records, show records, search for a record, update a record and delete a record. A user will have to enter their account information to add a record into the bank management system. After a user adds a record, they can perform other operations on it. In general, a Bank Management System assists banks in streamlining their operations, increasing efficiency, and improving customer service by offering a single platform for managing all elements of their organization.

Advanced Atm Management System using C++ (With Source Code)

Objective of the Bank Management System?

The system is intended to improve the efficiency and accuracy of a bank’s everyday operations. It makes the bank record keeping easy as it automates the manual record keeping system. A user can conveniently store a customers data and access it anytime easily by saving a lot of time.

Who can use this system?

Small to medium-sized banks and financial institutions that desire to automate their operations and deliver better services to their consumers might employ a basic bank management system. It can assist banks in lowering administrative expenses, improving customer service, and increasing revenues.

Overview of the UI:

***Account Information System***
        Select one option below
                 1–>Add record to file
                 2–>Show record from file
                 3–>Search Record from file
                 4–>Update Record
                 5–>Delete Record
                 6–>Quit
       Enter your choice:
The user will choose an option to perform the operation of their choice. To perform a specific operation on a particular bank record, the user will first have to select option 1 add a record, then only the user can perform an operation on it. 

Bank Management System using C++Source code:

You can directly use this code by copying it in your IDE to understand the working and then can create it by understanding the project.

#include<iostream>
#include<fstream>
#include<cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::fstream;
using std::ofstream;
using std::ifstream;
using std::ios;
class account_query
{
private:
    char account_number[20];
    char firstName[10];
    char lastName[10];
    float total_Balance;
public:
    void read_data();
    void show_data();
    void write_rec();
    void read_rec();
    void search_rec();
    void edit_rec();
    void delete_rec();
};
void account_query::read_data()
{
    cout<<"\nEnter Account Number: ";
    cin>>account_number;
    cout<<"Enter First Name: ";
    cin>>firstName;
    cout<<"Enter Last Name: ";
    cin>>lastName;
    cout<<"Enter Balance: ";
    cin>>total_Balance;
    cout<<endl;
}
void account_query::show_data()
{
    cout<<"Account Number: "<<account_number<<endl;
    cout<<"First Name: "<<firstName<<endl;
    cout<<"Last Name: "<<lastName<<endl;
    cout<<"Current Balance: Rs.  "<<total_Balance<<endl;
    cout<<"-------------------------------"<<endl;
}
void account_query::write_rec()
{
    ofstream outfile;
    outfile.open("record.bank", ios::binary|ios::app);
    read_data();
    outfile.write(reinterpret_cast<char *>(this), sizeof(*this));
    outfile.close();
}
void account_query::read_rec()
{
    ifstream infile;
    infile.open("record.bank", ios::binary);
    if(!infile)
    {
        cout<<"Error in Opening! File Not Found!!"<<endl;
        return;
    }
    cout<<"\n****Data from file****"<<endl;
    while(!infile.eof())
    {
        if(infile.read(reinterpret_cast<char*>(this), sizeof(*this)))
        {
            show_data();
        }
    }
    infile.close();
}
void account_query::search_rec()
{
    int n;
    ifstream infile;
    infile.open("record.bank", ios::binary);
    if(!infile)
    {
        cout<<"\nError in opening! File Not Found!!"<<endl;
        return;
    }
    infile.seekg(0,ios::end);
    int count = infile.tellg()/sizeof(*this);
    cout<<"\n There are "<<count<<" record in the file";
    cout<<"\n Enter Record Number to Search: ";
    cin>>n;
    infile.seekg((n-1)*sizeof(*this));
    infile.read(reinterpret_cast<char*>(this), sizeof(*this));
    show_data();
}
void account_query::edit_rec()
{
    int n;
    fstream iofile;
    iofile.open("record.bank", ios::in|ios::binary);
    if(!iofile)
    {
        cout<<"\nError in opening! File Not Found!!"<<endl;
        return;
    }
    iofile.seekg(0, ios::end);
    int count = iofile.tellg()/sizeof(*this);
    cout<<"\n There are "<<count<<" record in the file";
    cout<<"\n Enter Record Number to edit: ";
    cin>>n;
    iofile.seekg((n-1)*sizeof(*this));
    iofile.read(reinterpret_cast<char*>(this), sizeof(*this));
    cout<<"Record "<<n<<" has following data"<<endl;
    show_data();
    iofile.close();
    iofile.open("record.bank", ios::out|ios::in|ios::binary);
    iofile.seekp((n-1)*sizeof(*this));
    cout<<"\nEnter data to Modify "<<endl;
    read_data();
    iofile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
void account_query::delete_rec()
{
    int n;
    ifstream infile;
    infile.open("record.bank", ios::binary);
    if(!infile)
    {
        cout<<"\nError in opening! File Not Found!!"<<endl;
        return;
    }
    infile.seekg(0,ios::end);
    int count = infile.tellg()/sizeof(*this);
    cout<<"\n There are "<<count<<" record in the file";
    cout<<"\n Enter Record Number to Delete: ";
    cin>>n;
    fstream tmpfile;
    tmpfile.open("tmpfile.bank", ios::out|ios::binary);
    infile.seekg(0);
    for(int i=0; i<count; i++)
    {
        infile.read(reinterpret_cast<char*>(this),sizeof(*this));
        if(i==(n-1))
            continue;
        tmpfile.write(reinterpret_cast<char*>(this), sizeof(*this));
    }
    infile.close();
    tmpfile.close();
    remove("record.bank");
    rename("tmpfile.bank", "record.bank");
}
int main()
{
    account_query A;
    int choice;
    cout<<"***Account Information System***"<<endl;
    while(true)
    {
        cout<<"Select one option below ";
        cout<<"\n\t1-->Add record to file";
        cout<<"\n\t2-->Show record from file";
        cout<<"\n\t3-->Search Record from file";
        cout<<"\n\t4-->Update Record";
        cout<<"\n\t5-->Delete Record";
        cout<<"\n\t6-->Quit";
        cout<<"\nEnter your choice: ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            A.write_rec();
            break;
        case 2:
            A.read_rec();
            break;
        case 3:
            A.search_rec();
            break;
        case 4:
            A.edit_rec();
            break;
        case 5:
            A.delete_rec();
            break;
        case 6:
            exit(0);
            break;
        default:
            cout<<"\nEnter corret choice";
            exit(0);
        }
    }
    system("pause");
    return 0;
}

Now let us understand the code:-

  • We will start by writing the header of the code with the required libraries – iostream (input and output stream), fstream (file input and output), cstdlib.
  • Now we will create a  class called account_query, with member functions to perform various operations on the account records by choosing from the given options. Creating private data members inside the class for storing the account number, first name, last name, and total balance of an account.
  • We will create public member functions – read_data(), show_data(), write_rec(), read_rec(), search_rec(),  edit_rec(), delete_rec().
  • Now we will define the member functions outside the class using the scope resolution operator.
  • The read_data() function will read account number, first and last name and total balance from the user and store it in the class data members.
  • The show_data() function will display the account information stored in the data members on the console.
  • The write_rec() function will prompt the user to add a new account record to the file. It will ask the user to enter the account information, reads the data using read_data() function, and writes the data to the file in binary format using an ofstream.
  • The read_rec() function will read all the account records from the file and the display them on the console using show_data() function. The file will be opened in binary mode using an ifstream, reading the data using show_data() function and continuing until it will reach the end of the file.
  • The search_rec() function will let the user to search for an account record by their account number. The user will have to enter the account number, then it will search the file for the record and display it using show_data() function. It will use seekg() and read() functions of ifstream to navigate and read the file.
  • The edit_rec() function will allow the user to make changes to an existing account record. It will ask the user to input the account number of the record that needs to be changed, will read the existing data using read_data() function, then asking the user to enter the modified data using read_data(), and writing the modified data to the file using ofstream.
  • The delete_rec() function will delete a specified record from the binary file.. It will ask the user to enter the account number of the record to be deleted, read all records from the file using ifstream, writing all records except the one to be deleted to a temporary file using ofstream, and deletes the original file using the remove() function and renaming the temporary file to the original file using rename(). If the file does not exist then it will show an error statement – “Error in opening! File Not Found!!”.
  • Finally the main() function will display a menu of options for the user to choose from and upon choosing the operation to perform, the system calls the appropriate member function of the account_query class based on the user’s choice.
  • This sums up our project Bank Management System using C++.

Chess Game Using C++ (With Source Code)

Final Output:-

Here is an example to show how this project works.

Bank Management System using C++

Selecting option 1:Bank Management System using C++ (With Source Code)

Selecting option 2: Records are displayed

Bank Management System using C++

Selecting option 3:

Bank Management System using C++

Selecting option 4:

Bank Management System using C++

Selecting option 5:

Bank Management System using C++

 

Conclusion

We have reached the end of this article and have a lot more projects in C++ coming so stay tuned. We have started with awesome and fun projects for you all to understand C++. Learning C++ by creating fun projects makes learning easy and interesting.

Simple Blood Donation System using C++ (With Source Code)

If you enjoyed the article and learned something new today, let us know in the comments.

Thank you.

Happy Reading! 🙂

Follow: CodeWithRandom



Leave a Reply