Bank Management System In C++
Bank Management System In C++
The code is a simple banking system implemented in C++ using Object-Oriented Programming (OOP) principles. It allows the user to open a new account, deposit, withdraw, and display their account details.
Program code:-
#include<conio.h>
#include<stdio.h>
#include<iostream>
using namespace std;
class bank
{
char name[100],add[100],y;
int balance, amount, pin;
bool validPin = false;;
public:
void open_account ();
void deposite_money();
void withdraw_money ();
void display_account();
};
void bank::open_account()
{
system("cls");
cout<<"Enter your full name : ";
cin.ignore();
cin.getline(name,100);
cout<<"Enter your address : ";
cin.ignore();
cin.getline(add,100);
while (!validPin) {
cout << "Enter your desired 4-digit PIN: ";
cin >> pin;
if (pin >= 1000 && pin <= 9999) {
validPin = true;
cout << "PIN created successfully!" << endl;
} else {
cout << ".....Invalid PIN. Please enter a 4-digit numerical PIN....." << endl;
}
}
cout<<"Enter amount for deposite : ";
cin>>balance;
cout<<"---------- Your account is created ----------\n";
}
void bank::deposite_money()
{
int a ;
cout<<"Enter how much money you want to deposit: ";
cin>>a;
balance+=a;
cout<<"Your total deposit amount\n"<<balance<<endl;
}
void bank::display_account()
{
cout<<"Enter the name : "<<name<<endl;
cout<<"Enter your address : "<<add<<endl;
cout<<"Pin : "<<pin<<endl;
cout<<"Amount you deposite : "<<balance<<endl;
}
void bank::withdraw_money()
{
cout<<"withdraw -> ";
cout<<"Enter your amount for withdrawing: ";
cin>>amount;
balance=balance-amount;
cout<<"Now your total amount is left : "<<balance;
}
int main()
{
int ch,x,n;
bank obj;
system("cls");
system("color 0A");
do
{
cout<<" #####" ;
cout<<"\n ###########";
cout<<"\n #######################";
cout<<"\n#####################################\n";
cout<<"######## WELCOME TO LW BANK #########\n";
cout<<"#######################################\n";
cout<<"########## 1)Open account ###########\n";
cout<<"########## 2)Deposit money ###########\n";
cout<<"########## 3)WithDraw money ###########\n";
cout<<"########## 4)Display account###########\n";
cout<<"########## 5)Exit ###########\n";
cout<<"\nPlease sir, select the option from above: ";
cin>>ch;
switch(ch)
{
case 1:"01)Open account \n";
obj.open_account ();
break;
case 2:"02)Deposit money \n";
obj.deposite_money();
break;
case 3:"03)WithDraw money \n";
obj.withdraw_money ();
break;
case 4:"04)Display account\n";
obj.display_account();
break;
case 5:
if(ch==5)
{
cout<< "exit";
}
break;
default:{
cout<<"Enter valid option, please try again... \n";
}
}
cout<<"\nWant to select next step then please press: Y/y \n";
cout<<"If you want to exit then please press: N/n \n";
x=getch();
if(x=='n' || x=='N')
cout<<"Exit";
}
while (x=='y' || x=='Y');
getch();
return 0;
}
Output:-
The program starts by defining a class bank that contains the member variables name, add, y, balance, amount, and pin, and member functions 'open_account()', 'deposite_money()', 'withdraw_money()', and 'display_account()'. The 'open_account()'function prompts the user to enter their name, address, desired 4-digit PIN, and initial balance. The 'deposite_money()'function allows the user to deposit money into their account, and withdraw_money() allows them to withdraw money. The 'display_account()'function displays the user's account information, including their name, address, PIN, and account balance.
The main function of the program displays a menu with options for the user to select. The user can select an option by entering a number from 1 to 5. If the user selects the "Open account" option, the 'open_account()'function is called to create a new account. If they select the "Deposit money" option, the 'deposite_money()'function is called to add money to the account. If they select the "Withdraw money" option, the 'withdraw_money()'function is called to deduct money from the account. If they select the "Display account" option, the 'display_account()'function is called to display their account information. If they select the "Exit" option, the program terminates.
The program uses a do-while loop to allow the user to select multiple options until they choose to exit. After each operation, the user is prompted to enter 'Y' or 'y' to continue or 'N' or 'n' to exit. If the user chooses to exit, the program terminates.
In conclusion, the program is a basic banking system that demonstrates the use of classes, functions, and loops in C++. The program can be improved by adding more features such as transferring funds, adding interest to the account balance, and ensuring the security of user information.
Thank You!!!
Comments
Post a Comment