We have designed this Bank Management System with C++ to simulate typical banking operations. It has been built to provide a hands-on experience with concepts of Object-Oriented Programming, file handling, and system design. This C++ project allows users to create and manage bank accounts, execute transactions, and handle other banking tasks, all through a command-line interface.
Introduction
The Bank management system deals with the concept of making a complete record of a customer’s account. The system utilizes key concepts from Object-Oriented Programming and allows users to manage their bank accounts in an interactive way through the following operations:
- Creating a new bank account
- Depositing money into an account
- Withdrawing money from an account
- Checking the balance of an account
- Displaying the details of all account holders
- Closing an account
- Modifying the details of an account
Objectives
The main objectives of this Bank Management System with C++ are as follows:
1. Implement a simple bank management system in C++ with object-oriented programming concepts and a text-based user interface for users to interact with the system. Our system will include options for creating new accounts, depositing money, withdrawing money, viewing account details, and more.
2. Use a class Bank_account to represent individual bank accounts. Each Bank_account object encapsulates data members like account number, account holder’s name, account type, and deposit amount.
3. Allow the creation of a new bank account with user-provided details such as account number, account holder’s name, account type, and initial deposit amount. Other functions provided are:
- Enable viewing details of a specific account given the account number.
- Allow modification of an existing account’s details.
- Enable deposit of an amount into an account or withdrawal from an account.
- Provide the ability to delete an account.
- Display all the accounts held in the bank, providing a brief report of each account.
4. Manage data persistence by using file I/O operations to store and retrieve bank account data. The program saves all the accounts in a binary file named “account.dat”.
5. Loop the main menu until the user chooses to exit, enabling multiple operations in a single run of the program.
Requirements
1. C++ Compiler: You need a C++ compiler to compile and run this code. Some popular C++ compilers include GCC, Clang, and MSVC. Integrated Development Environments (IDEs) like Code::Blocks, Visual Studio, or online platforms like Repl.it are also suitable for running this code.
2. Basic Understanding of C++: This code is written in C++, so having a basic understanding of C++ programming is crucial. This includes knowledge of classes and objects, file I/O, control statements (like if, switch, while), and input/output operations.
3. Operating System: As the code uses a system(“CLS”) command, it is supposed to be run in a Windows environment because “CLS” is a command specific to the Windows command prompt. If you’re running on a Unix-like system (like Linux or macOS), you might need to replace “CLS” with “clear”.
4. File System Permissions: This program creates and manipulates files (“account.dat” and “Temp.dat”) in the same directory as the executable. You need to ensure that the directory where you run the program has write permissions.
Source Code
#include<iostream> #include<fstream> #include<cctype> #include<iomanip> using namespace std; class Bank_account { int acno; char name[50]; int deposit; char type; public: void create_account(); void show_account() const; void modify(); void dep(int); void draw(int); void report() const; int retacno() const; int retdeposit() const; char rettype() const; }; void Bank_account::create_account() { system("CLS"); cout<<"\n\t\t\tEnter the Account No. : "; cin>>acno; cout<<"\n\n\t\t\tEnter the Name of the Account holder : "; cin.ignore(); cin.getline(name,50); cout<<"\n\t\t\tEnter Type of the Account (C/S) : "; cin>>type; type=toupper(type); cout<<"\n\t\t\tEnter The Initial amount : "; cin>>deposit; cout<<"\n\n\t\t\tAccount Created.."; } void Bank_account::show_account() const { cout<<"\n\t\t\tAccount No. : "<<acno; cout<<"\n\t\t\tAccount Holder Name : "; cout<<name; cout<<"\n\t\t\tType of Account : "<<type; cout<<"\n\t\t\tBalance amount : "<<deposit; } void Bank_account::modify() { cout<<"\n\t\t\tAccount No. : "<<acno; cout<<"\n\t\t\tModify Account Holder Name : "; cin.ignore(); cin.getline(name,50); cout<<"\n\t\t\tModify Type of Account : "; cin>>type; type=toupper(type); cout<<"\n\t\t\tModify Balance amount : "; cin>>deposit; } void Bank_account::dep(int x) { deposit+=x; } void Bank_account::draw(int x) { deposit-=x; } void Bank_account::report() const { cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl; } int Bank_account::retacno() const { return acno; } int Bank_account::retdeposit() const { return deposit; } char Bank_account::rettype() const { return type; } void write_account(); void display_sp(int); void modify_account(int); void delete_account(int); void display_all(); void deposit_withdraw(int, int); int main() { char ch; int num; do { system("CLS"); cout<<"\n\n\t\t\t\t======================\n"; cout<<"\t\t\t\tBANK MANAGEMENT SYSTEM"; cout<<"\n\t\t\t\t======================\n"; cout<<"\t\t\t\t ::MAIN MENU::\n"; cout<<"\n\t\t\t\t1. NEW ACCOUNT"; cout<<"\n\t\t\t\t2. DEPOSIT AMOUNT"; cout<<"\n\t\t\t\t3. WITHDRAW AMOUNT"; cout<<"\n\t\t\t\t4. BALANCE ENQUIRY"; cout<<"\n\t\t\t\t5. ALL ACCOUNT HOLDER LIST"; cout<<"\n\t\t\t\t6. CLOSE AN ACCOUNT"; cout<<"\n\t\t\t\t7. MODIFY AN ACCOUNT"; cout<<"\n\t\t\t\t8. EXIT"; cout<<"\n\n\t\t\t\tSelect Your Option (1-8): "; cin>>ch; switch(ch) { case '1': write_account(); break; case '2': system("CLS"); cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num; deposit_withdraw(num, 1); break; case '3': system("CLS"); cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num; deposit_withdraw(num, 2); break; case '4': system("CLS"); cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num; display_sp(num); break; case '5': display_all(); break; case '6': system("CLS"); cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num; delete_account(num); break; case '7': system("CLS"); cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num; modify_account(num); break; case '8': system("CLS"); cout<<"\n\n\t\t\tBrought To You By code-projects.org"; break; default :cout<<"\a"; } cin.ignore(); cin.get(); }while(ch!='8'); return 0; } void write_account() { Bank_account ac; ofstream outFile; outFile.open("account.dat",ios::binary|ios::app); ac.create_account(); outFile.write(reinterpret_cast<char *> (&ac), sizeof(Bank_account)); outFile.close(); } void display_sp(int n) { Bank_account ac; bool flag=false; ifstream inFile; inFile.open("account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<"\n\t\t\tBALANCE DETAILS\n"; while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(Bank_account))) { if(ac.retacno()==n) { ac.show_account(); flag=true; } } inFile.close(); if(flag==false) cout<<"\n\n\t\t\tAccount number does not exist"; } void modify_account(int n) { bool found=false; Bank_account ac; fstream File; File.open("account.dat",ios::binary|ios::in|ios::out); if(!File) { cout<<"File could not be open !! Press any Key..."; return; } while(!File.eof() && found==false) { File.read(reinterpret_cast<char *> (&ac), sizeof(Bank_account)); if(ac.retacno()==n) { ac.show_account(); cout<<"\n\n\t\t\tEnter The New Details of account"<<endl; ac.modify(); int pos=(-1)*static_cast<int>(sizeof(Bank_account)); File.seekp(pos,ios::cur); //fncallat1353 File.write(reinterpret_cast<char *> (&ac), sizeof(Bank_account)); cout<<"\n\n\t\t\tRecord Updated"; found=true; } } File.close(); if(found==false) cout<<"\n\n\t\t\tRecord Not Found "; } void delete_account(int n) { Bank_account ac; ifstream inFile; ofstream outFile; inFile.open("account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } outFile.open("Temp.dat",ios::binary); inFile.seekg(0,ios::beg); while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(Bank_account))) { if(ac.retacno()!=n) { outFile.write(reinterpret_cast<char *> (&ac), sizeof(Bank_account)); } } inFile.close(); outFile.close(); remove("account.dat"); rename("Temp.dat","account.dat"); cout<<"\n\nRecord Deleted .."; } void display_all() { system("CLS"); Bank_account ac; ifstream inFile; inFile.open("account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n"; cout<<"====================================================\n"; cout<<"A/c no. NAME Type Balance\n"; cout<<"====================================================\n"; while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(Bank_account))) { ac.report(); } inFile.close(); } void deposit_withdraw(int n, int option) { int amt; bool found=false; Bank_account ac; fstream File; File.open("account.dat", ios::binary|ios::in|ios::out); if(!File) { cout<<"File could not be open !! Press any Key..."; return; } while(!File.eof() && found==false) { File.read(reinterpret_cast<char *> (&ac), sizeof(Bank_account)); if(ac.retacno()==n) { ac.show_account(); if(option==1) { cout<<"\n\n\t\t\tTO DEPOSITSS AMOUNT"; cout<<"\n\n\t\t\tEnter The amount to be deposited: "; cin>>amt; ac.dep(amt); } if(option==2) { cout<<"\n\n\t\t\tTO WITHDRAW AMOUNT"; cout<<"\n\n\t\t\tEnter The amount to be withdraw: "; cin>>amt; int bal=ac.retdeposit()-amt; if(bal<0) cout<<"Insufficience balance"; else ac.draw(amt); } int pos=(-1)*static_cast<int>(sizeof(ac)); File.seekp(pos,ios::cur);//fn1353 File.write(reinterpret_cast<char *> (&ac), sizeof(Bank_account)); cout<<"\n\n\t\t\tRecord Updated"; found=true; } } File.close(); if(found==false) cout<<"\n\n\t\t\tRecord Not Found "; }
Explanation of the Code
Let us have a look at the functionalities of the above-written code for the Bank management system with C++:
Bank_account Class Methods:
- create_account(): This function prompts the user to enter details such as account number, name, account type (C for Checking, S for Saving), and the initial deposit amount. It stores this information in the object’s member variables.
- show_account() const: This function displays the details of an account, such as the account number, account holder’s name, type of account, and the balance amount.
- modify(): This function modifies the details of an existing account. It prompts the user to enter the new account holder’s name, type of account, and balance amount.
- dep(int x): This function is used to deposit an amount (x) into the account. It increases the account’s deposit amount by the entered amount (x).
- draw(int x): This function is used to withdraw an amount (x) from the account. It decreases the account’s deposit amount by the entered amount (x).
- report() const: This function is used to print the account’s details in a specific format suitable for listing all accounts.
- retacno() const, retdeposit() const, and rettype() const: These functions return the account number, deposit amount, and account type respectively. They are used for various operations, such as searching for an account or verifying the balance.
Main Function: The main function runs a loop that prints a menu to the user and executes the user’s chosen operation. The operations are performed using a switch statement that calls different functions based on user input.
Other Functions:
- write_account(): This function is used to create a new account. It creates an object of the Bank_account class, calls the create_account() function to get the account details from the user, and writes the object to the “account.dat” file.
- display_sp(int n): This function displays the details of a specific account. It opens the “account.dat” file, reads each account, and displays the account details if the account number matches the input (n).
- modify_account(int n): This function modifies the details of a specific account. It opens the “account.dat” file, reads each account until it finds the account with the number (n), modifies the details using the modify() function, and writes the updated account back to the file.
- delete_account(int n): This function deletes a specific account. It opens the “account.dat” file and the “Temp.dat” file, reads each account from “account.dat”, and writes the account to “Temp.dat” only if the account number does not match the input (n). Then it deletes “account.dat” and renames “Temp.dat” to “account.dat”.
- display_all(): This function displays all accounts. It opens the “account.dat” file, reads each account, and displays its details using the report() function.
- deposit_withdraw(int n, int option): This function handles deposit and withdrawal operations. It opens the “account.dat” file, reads each account until it finds the account with the number (n), and then either deposits or withdraws an amount based on the input (option). It then writes the updated account back to the file.
Output
There are 8 options in the main menu, and the user can select any of them one by one.
Selecting option 1 will create a new account in which the user is asked for the necessary details like account number, name of the account holder, account type, and initial amount. Thus, the account is created successfully.
Conclusion
The Bank management system with C++ is a basic replica of logic for different operations that can be performed in a bank for opening accounts and managing the same by the customer. This project aids in learning how real-world systems can be modeled and implemented in C++ and demonstrates practical usage of file handling for data persistence.

Cisco Ramon is an American software engineer who has experience in several popular and commercially successful programming languages and development tools. He has been writing content since last 5 years. He is a Senior Manager at Rude Labs Pvt. Ltd.
0 Comments