![]() |
VOOZH | about |
Prerequisite: Switch Case in C/C++
Problem Statement:
Write a program to build a simple Bank Management System using C++ which can perform the following operations:
Approach: Below is the approach to do the above operations:
// Method to Open a new account.
void Bank::open_account()
{
// Enter Name of a Customer
name = "xyz Gupta";
cout << "Enter your full name: "
<< name << endl;
// Enter City of a Customer
address = "Banglore";
cout << "Enter your address: "
<< address << endl;
// Enter Type of Account(Saving or Current)
acc_type = 'S';
cout << "Type of account you want "
<< "to open saving(S) or Current(C): "
<< acc_type << endl;
// Enter Amount to deposit
balance = 8000;
cout << "Enter the amount for deposit: "
<< balance << endl;
cout << "Account Created Successfully";
}
2. Deposit Money: Deposit money function is created to deposit money to the account by asking amount by the customer.
It will ask the amount and add it to the available balance.
Total Balance = Available Balance + Deposited Amount
// Method to add balance in account
void Bank::deposit_money()
{
int Amount;
// Enter Amount to Deposit
Amount = 9500;
cout << "Enter How much money "
<< "you want to deposit: "
<< Amount << endl;
// Total_Balance = Available_Balance + Amount
balance += Amount;
cout << "\Available Balance: "
<< balance;
}
3. Display Account: Display Account function will show the details of the customer like name, address, type of account and available balance.
// Method to Display the details of account
void Bank::display_account()
{
cout << "Name: " << name << endl
<< "Address: " << address << endl
<< "Type: " << acc_type << endl
<< "Balance: " << balance << endl
<< endl;
}
4. Withdraw Money: Withdraw money function is created to withdraw money from the account by asking amount by the customer.
It will ask the amount and subtract it from the available balance.
Total Balance = Available Balance - Withdrawal Amount
void Bank::withdraw_money()
{
float amount;
// Enter Amount to Withdraw
amount = 3200;
cout << "Enter How much money "
<< "you want to withdraw: "
<< amount << endl;
// Total_Balance = Available_Balance - Withdrawal_Amount
balance -= amount;
cout << "Available balance: "
<< balance;
}
Below is the implementation of the above approach:
1) Open account Enter your full name: Aman Jhurani Enter your address: Surat What type of account you want to open saving(S) or Current(C): S Enter How much money you want to deposit: 8000 Account Created Successfully ------------------------------------------------- 2) Deposit account Enter how much money you want to deposit: 9500 Available Balance: 17500 ------------------------------------------------- 2) Withdraw money Enter how much money you want to withdraw: 3200 Available balance: 14300 ------------------------------------------------- 4) Display Account Name: Aman Jhurani Address: Surat Type: S Balance: 14300 -------------------------------------------------
Time Complexity: O(1), As each function is performing constant time operations
Auxiliary Space: O(1), As constant extra space is used.