Open In App

Menu-Driven Program for Bank Management System

Improve
Improve
Like Article
Like
Save
Share
Report

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: 

  1. Open account
  2. Deposit Money
  3. Withdraw Money
  4. Display Account

Approach: Below is the approach to do the above operations: 

  1. Open Account: This method takes details from the customer like name, address, type of account, and depositing money and creating a new account.
// 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: 

CPP




// C++ program to implement
// Bank Management System
 
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
using namespace std;
 
class Bank {
    string name, address;
    char acc_type;
    float balance;
 
public:
    void open_account();
    void deposit_money();
    void withdraw_money();
    void display_account();
};
 
// Function to open the account
void Bank::open_account()
{
    name = "Aman Jhurani";
    cout << "Enter your full name: "
         << name << endl;
    address = "Surat";
    cout << "Enter your address: "
         << address << endl;
    acc_type = 'S';
    cout << "What type of account you want"
         << " to open saving(S) or Current(C): "
         << acc_type << endl;
    balance = 8000;
    cout << "Enter How much money you want to deposit: "
         << balance << endl;
    cout << "Account Created Successfully";
}
 
// Function to deposit the account
void Bank::deposit_money()
{
    int Amount;
    Amount = 9500;
    cout << "Enter how much money"
         << " you want to deposit: "
         << Amount << endl;
    balance += Amount;
    cout << "\n Available Balance: "
         << balance;
}
 
// Function to display the account
void Bank::display_account()
{
    cout << "Name: " << name << endl
         << "Address: " << address << endl
         << "Type: " << acc_type << endl
         << "Balance: " << balance << endl
         << endl;
}
 
// Function to withdraw the account
void Bank::withdraw_money()
{
    float amount;
    amount = 3200;
    cout << "Enter how much money "
         << "you want to withdraw: "
         << amount << endl;
    balance -= amount;
    cout << "\n Available balance: "
         << balance;
}
 
// Driver code
int main()
{
    int choice;
 
    // Creating Customer Object of Bank Class
    Bank customer;
 
    cout << "\n1) Open account \n\n";
    // Calling open_account() function
    // through customer object.
    customer.open_account();
    cout << "\n------------------------"
         << "-------------------------\n";
 
    cout << "\n2) Deposit account \n\n";
    // Calling deposit_money() function
    // through customer object.
    customer.deposit_money();
    cout << "\n------------------------"
         << "-------------------------\n";
 
    cout << "\n2) Withdraw money \n\n";
    // Calling withdraw_money() function
    // through customer object.
    customer.withdraw_money();
    cout << "\n------------------------"
         << "-------------------------\n";
 
    cout << "\n4) Display Account \n\n";
    // Calling display_account() function
    // through customer object.
    customer.display_account();
    cout << "\n------------------------"
         << "-------------------------\n";
 
    return 0;
}


Java




// Java program for above approach
package GeeksforGeeks;
import java.util.Scanner;
import java.io.*;
 
class Bank
{
  private String name;
  private String address;
  private char acc_type;
  private float balance;
 
  // Constructor of class Bank
  Bank(){
 
  // Initializing values  0 for float
  // and null for String and character
  name=" ";
  address=" ";
  acc_type=' ';
  balance=0;
 }
   
// Method to open the account
void open_account()
{
    name = "Aman Jhurani";
    System.out.println("Enter your full name: ");
    address = "Surat";
    System.out.println("Enter your address: ");    
    acc_type = 'S';
    System.out.println("What type of account you want");
    System.out.println(" to open saving(S)   or Current(C): ");
    balance = 8000;
    System.out.println("Enter How much money   you want to deposit: ");
    System.out.println("Account Created   Successfully");
}
   
// Method to deposit the account
void deposit_money()
{
    int Amount;
    Amount = 9500;
    System.out.println( "Enter how much money you want to deposit: "+ Amount);
    balance += Amount;
    System.out.println( "\n Available Balance: "
                                      + balance);   
}
   
// Method to display the account
void display_account()
{
    System.out.println( "Name: " +name);
    System.out.println("Address: "+ address);
    System.out.println("Type: "+acc_type);
    System.out.println("Balance: " +balance);
}
   
// Method to withdraw the account
void withdraw_money()
{
    float amount;
    amount = 3200;
    System.out.println("Enter how much money  you want to withdraw: "+amount );
    balance -= amount;
    System.out.println("\n Available balance: "
                                        + balance);      
}
   
// Driver code
public static void main(String[] args)
{
    int choice;
   
    // Creating Customer Object of Bank Class
    Bank customer=new Bank();
   
    System.out.println("\n1) Open account \n");
     
    // Calling open_account() method
    // through customer object.
    customer.open_account();
    System.out.println("\n-----------------------\n");
   
    System.out.println("\n2) Deposit account \n");
     
    // Calling deposit_money()   method
    // through customer object.
    customer.deposit_money();
    System.out.println("\n-----------------------\n");
   
    System.out.println("\n3) Withdraw money \n\n");
     
    // Calling withdraw_money()  method
    // through customer object.
    customer.withdraw_money();
    System.out.println("\n-----------------\n");
    System.out.println("\n4) Display Account \n\n");
     
    // Calling display_account()  method
    // through customer object.
    customer.display_account();
    System.out.println("\n------------------------\n"); 
 }
}
                        
//This code is contributed by sahilnaik2712


Python3




# Python program to implement
# Bank Management System
 
class Bank:
    # Initialize instance variables
    def init(self):
        self.name = ""
        self.address = ""
        self.acc_type = ""
        self.balance = 0.0
         
    # Function to open the account
    def open_account(self):
      self.name = "Aman Jhurani"
      print("Enter your full name: ", self.name)
      self.address = "Surat"
      print("Enter your address: ", self.address)
      self.acc_type = 'S'
      print(
          "What type of account you want to open saving(S) or Current(C): ", self.acc_type)
      self.balance = 8000
      print("Enter How much money you want to deposit: ", self.balance)
      print("Account Created Successfully")
 
    # Function to deposit the account
    def deposit_money(self):
      Amount = 9500
      print("Enter how much money you want to deposit: ", Amount)
      self.balance += Amount
      print("\nAvailable Balance: ", self.balance)
 
    # Function to display the account
    def display_account(self):
      print("Name: ", self.name)
      print("Address: ", self.address)
      print("Type: ", self.acc_type)
      print("Balance: ", self.balance)
 
    # Function to withdraw the account
    def withdraw_money(self):
      amount = 3200
      print("Enter how much money you want to withdraw: ", amount)
      self.balance -= amount
      print("\nAvailable balance: ", self.balance)
 
# Driver code
if __name__ == "__main__" :
   
  # Creating Customer Object of Bank Class
  customer = Bank()
 
  print("\n1) Open account\n\n")
  # Calling open_account() function through customer object
  customer.open_account()
  print("\n------------------------\n")
 
  print("\n2) Deposit account\n\n")
  # Calling deposit_money() function through customer object
  customer.deposit_money()
  print("\n------------------------\n")
 
  print("\n2) Withdraw money\n\n")
  # Calling withdraw_money() function through customer object
  customer.withdraw_money()
  print("\n------------------------\n")
 
  print("\n4) Display Account\n\n")
  # Calling display_account() function through customer object
  customer.display_account()
  print("\n------------------------\n")


C#




// C# program to implement Bank Management System
 
using System;
 
class Bank {
    string name, address;
    char acc_type;
    float balance;
    // Function to open the account
    public void open_account()
    {
        name = "Aman Jhurani";
        Console.WriteLine("Enter your full name: " + name);
        address = "Surat";
        Console.WriteLine("Enter your address: " + address);
        acc_type = 'S';
        Console.WriteLine(
            "What type of account you want to open saving(S) or Current(C): "
            + acc_type);
        balance = 8000;
        Console.WriteLine(
            "Enter How much money you want to deposit: "
            + balance);
        Console.WriteLine("Account Created Successfully");
    }
 
    // Function to deposit the account
    public void deposit_money()
    {
        int Amount = 9500;
        Console.WriteLine(
            "Enter how much money you want to deposit: "
            + Amount);
        balance += Amount;
        Console.WriteLine("\nAvailable Balance: "
                          + balance);
    }
 
    // Function to withdraw the account
    public void withdraw_money()
    {
        float amount = 3200;
        Console.WriteLine(
            "Enter how much money you want to withdraw: "
            + amount);
        balance -= amount;
        Console.WriteLine("\nAvailable balance: "
                          + balance);
    }
 
    // Function to display the account
    public void display_account()
    {
        Console.WriteLine("Name: " + name);
        Console.WriteLine("Address: " + address);
        Console.WriteLine("Type: " + acc_type);
        Console.WriteLine("Balance: " + balance + "\n");
    }
}
 
class Program {
    static void Main(string[] args)
    {
        int choice;
        // Creating Customer Object of Bank Class
        Bank customer = new Bank();
 
        Console.WriteLine("\n1) Open account\n\n");
        // Calling open_account() function through customer
        // object.
        customer.open_account();
        Console.WriteLine("------------------------\n");
 
        Console.WriteLine("\n2) Deposit account\n\n");
        // Calling deposit_money() function through customer
        // object.
        customer.deposit_money();
        Console.WriteLine("------------------------\n");
 
        Console.WriteLine("\n2) Withdraw money\n\n");
        // Calling withdraw_money() function through
        // customer object.
        customer.withdraw_money();
        Console.WriteLine("------------------------\n");
 
        Console.WriteLine("\n4) Display Account\n\n");
        // Calling display_account() function through
        // customer object.
        customer.display_account();
        Console.WriteLine("------------------------\n");
 
        Console.ReadKey();
    }
}


Javascript




// JavaScript equivalent of the above code
 
class Bank {
  // Initialize instance variables
  constructor() {
    this.name = "";
    this.address = "";
    this.acc_type = "";
    this.balance = 0.0;
  }
  // Function to open the account
  open_account() {
    this.name = "Aman Jhurani";
    console.log("Enter your full name: ", this.name);
    this.address = "Surat";
    console.log("Enter your address: ", this.address);
    this.acc_type = "S";
    console.log("What type of account you want to open saving(S) or Current(C): ", this.acc_type);
    this.balance = 8000;
    console.log("Enter How much money you want to deposit: ", this.balance);
    console.log("Account Created Successfully");
  }
 
  // Function to deposit the account
  deposit_money() {
    let Amount = 9500;
    console.log("Enter how much money you want to deposit: ", Amount);
    this.balance += Amount;
    console.log("\nAvailable Balance: ", this.balance);
  }
 
  // Function to display the account
  display_account() {
    console.log("Name: ", this.name);
    console.log("Address: ", this.address);
    console.log("Type: ", this.acc_type);
    console.log("Balance: ", this.balance);
  }
 
  // Function to withdraw the account
  withdraw_money() {
    let amount = 3200;
    console.log("Enter how much money you want to withdraw: ", amount);
    this.balance -= amount;
    console.log("\nAvailable balance: ", this.balance);
  }
}
 
// Driver code
const customer = new Bank();
 
console.log("\n1) Open account\n\n");
// Calling open_account() function through customer object
customer.open_account();
console.log("\n------------------------\n");
 
console.log("\n2) Deposit account\n\n");
// Calling deposit_money() function through customer object
customer.deposit_money();
console.log("\n------------------------\n");
 
console.log("\n2) Withdraw money\n\n");
// Calling withdraw_money() function through customer object
customer.withdraw_money();
console.log("\n------------------------\n");
 
console.log("\n4) Display Account\n\n");
// Calling display_account() function through customer object
customer.display_account();
console.log("\n------------------------\n");


Output

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.



Last Updated : 12 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads