In this blog, we will create a basic banking system in C++ using object-oriented programming. This project will help you understand how to model real-world entities using classes and implement common banking operations like deposit, withdrawal, and viewing account details.
Building a Simple Banking System in C++ Using OOP Concepts
Why Use OOP for a Banking System?
Object-oriented programming allows us to represent complex systems as objects. For a banking system, each account becomes an object that holds its data and operations. This approach keeps the program organized, reusable, and easier to maintain.
Features
-
Create an account with a name, account number, and initial balance.
-
Deposit money into the account.
-
Withdraw money from the account.
-
Display current account details.
#include <iostream> using namespace std; class BankAccount{ private: string name; int accountNumber; double balance; public: BankAccount(string accName,int accNum,double initialBalance){ name=accName; accountNumber=accNum; balance=initialBalance; } void deposit(double amount){ balance+=amount; cout<< "₹" <<amount<<" deposited successfully."<<endl; } void withdraw(double amount){ if(amount>balance) { cout<<"Insufficient balance! Withdrawal failed."<<endl; } else{ balance-=amount; cout<<"₹"<<2 amount<<" withdrawn successfully."<<endl; } } void display() { cout << "---------------------------" << endl; cout << "Account Holder: " << name << endl; cout << "Account Number: " << accountNumber << endl; cout << "Current Balance: ₹" << balance << endl; cout << "---------------------------" << endl; } }; int main() { BankAccount myAccount("Fahim", 12345, 1000.0); myAccount.display(); myAccount.deposit(500); myAccount.withdraw(200); myAccount.display(); return 0; }
Output:
—————————
Account Holder: Fahim
Account Number: 12345
Current Balance: ₹1000
—————————
₹500 deposited successfully.
₹200 withdrawn successfully.
—————————
Account Holder: Fahim
Account Number: 12345
Current Balance: ₹1300
—————————