Bank Account Information Project using C++

Bank Account Information Project using C++(Source Code)

Bank Account Information Project using C++(Source Code)

Hello, coders. Welcome to the codewithrandom blog. In this article, we will learn how to create a Bank Account Information Project using C++.

Bank Account Information System is based on a concept of recording customerā€™s account details.

In this project the user can perform tasks such as adding a record to file, show a record from the file, Search records, update a record and delete a record. Thereā€™s no login system for this project. All the main features for Bank Account Information system are set in this project.

This whole system is based on a concept to create and generate bank accountā€™s details in the form of records in a file. In this system, the user can add, search, delete, view and update customerā€™s account details. Adding Account details includes Customerā€™s Account Number, First and last name, Total Amount Deposited/Remaining in the bank. This mini project is developed in order to store and retrieve customerā€™s account detail in a short period of time as it is not time-consuming. The whole project is designed in ā€˜C++ā€™ language, different variables and strings have been used for the development. This project is easy to understand and operate by the users.

Tourist Reservation System using C++(With Source Code)

Here is the UI of this project:-Ā 

The UI of the game is simple.

Bank Account Information Project using C++

Creating a Bank Account Information Project using C++ Source Code:

You can take help from the code to learn and create the Bank Account Information Project or you can directly copy the source code into your IDE.

#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()
{
    system("cls");
    cout<<"\nEnter Account Number: ";
    cin>>account_number;
    cout<<"-------------------------";
    cout<<"\nEnter First Name: ";
    cin>>firstName;
    cout<<"-------------------------";
    cout<<"\nEnter Last Name: ";
    cin>>lastName;
    cout<<"-------------------------";
    cout<<"\nEnter Balance: ";
    cin>>total_Balance;
    cout<<"-------------------------";
    cout<<endl;
    cout<<"\n Account Details Saved!!\n\n";
    system("PAUSE");
   
}
void account_query::show_data()
{
    system("cls");
    cout<<" : ACCOUNT DETAILS : ";
    cout<<"\n\nAccount Number: "<<account_number<<endl;
    cout<<"-------------------------";
    cout<<"\nFirst Name: "<<firstName<<endl;
    cout<<"-------------------------";
    cout<<"\nLast Name: "<<lastName<<endl;
    cout<<"-------------------------";
    cout<<"\nCurrent Balance: Rs.  "<<total_Balance<<endl;
    cout<<"-------------------------------"<<endl;
    system("PAUSE");
    
}
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()
{
    system("cls");
    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)>0)
        ){
            show_data();
        }
    }
    infile.close();
    system("PAUSE");
}
void account_query::search_rec()
{
    system("cls");
    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--------------------------------";
    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();
    system("PAUSE");
}
void account_query::edit_rec()
{
    system("cls");
    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));
    system("PAUSE");
}
void account_query::delete_rec()
{
    system("cls");
    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");
    system("PAUSE");
}
int main()
{
    
    system("cls");
    account_query A;
    int choice;
    cout<<"\n  *****Account Information System*****"<<endl;
    while(true)
    {
    	system("cls");
    	cout<<"\n  *****Account Information System*****"<<endl;
        cout<<"\t\nSelect Any Option Below \n";
        cout<<"\n\t-------------------------";
        cout<<"\n\t1>> Add record to file";
        cout<<"\n\t-------------------------";
        cout<<"\n\t2>> Show record from file";
        cout<<"\n\t-------------------------";
        cout<<"\n\t3>> Search Record from file";
        cout<<"\n\t-------------------------";
        cout<<"\n\t4>> Update Record";
        cout<<"\n\t-------------------------";
        cout<<"\n\t5>> Delete Record";
        cout<<"\n\t-------------------------";
        cout<<"\n\t6>> Quit";
        cout<<"\n\t-------------------------";
        cout<<"\n\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:-

  • After writing the header of the code with the required libraries, we have created a class account_query. Inside the class we have used public and private access specifiers ro declare the functions for the bank info system operations. The private access-specifier contains the following functions – char account_number[20]; char firstName[10]; char lastName[10]; float total_Balance; and the public access-specifier contains void read_data(); void show_data(); void write_rec(); void read_rec(); void search_rec(); void edit_rec(); void delete_rec();
  • Now we will define the functions outside the class using scope-resolution operator.
  • The read_data() function will ask the user to enter the following details –
    Enter Account Number:
    Enter First Name:
    Enter Last Name:
    Enter Balance:
    and after the details have been entered and saved, it will display – Account Details Saved!!
  • The show_data() function will display all the information and the enteries of records which the user has entered using the read_data() function.
  • The write_rec() function will use ofstream. This class describes an output stream. It is used to create files and to write data to files.
  • The read_rec() function contains the ifstream which is used used to read data from files. This class describes an input stream, a program that reads data from files and displays it.
  • The search_rec() allows you to search for a particular entry/record from the bank account information file by entering a choice. The function will return that record as a result. It can be beneficial to use when we have a lot of records in the bank account information file. This function can be performed after adding the records in the file.
  • The edit_rec() function allows you to edit the entries. We can changes the values of the entries of the bank account information entered. The record will be edited by entering the entry number of that record you wish to edit. This function will display the number of records in the file. If the record number enter does not exist then an error will appear – Error in opening! File Not Found!!
  • The delete_rec() function allows you to delete entries one by one permanently from the database. We will have to enter the record number to delete it.
  • The main() functionĀ contains system(ā€œclsā€); ā€“ Used to clear the screen. A while loop is used to first display all the functions inside the Bank Account Information system from which the user can select to perform the functions- add record, show records, search record, update record, Delete record and quit. The user will enter the choice. Using a switch-case control statement to select the function to be performed.

Electricity Bill generator using C++ (With Source Code)

OUTPUT:- with example record

Bank Account Information Project using C++

1>> Add record to file

Bank Account Information Project using C++

2>> Show record from file

Bank Account Information Project 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.

Bank Management 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