C++ Bank Application Program Using Classes And Object

Write A C++ Bank Application Program Which Takes User Input as how many accounts, name, password, display, deposit, transfer, sort, withdraw and delete, etc.

C++ Bank Application Program Using Classes And Object

#include<iostream>
using namespace std;
int n, i, k, m, s;
class bank
{
  int acc_no;
  string name;
  string password;
  int balance;
public:
    bank ()
  {
    acc_no = 0;
  }
  void create_account ();
  void deposit ();
  int generate_accno (int i);
  void withdraw ();
  void transfer (bank);
  void display ();
  static void sort (bank a[]);
  void delete_account ();
};

int main ()
{
  bank b[100];
  cout << "enter the number of customers: ";
  cin >> n;
  int choice;
  while (choice != 9)
    {
      cout <<
	"1. Create account\n2. Dispaly all accounts \n3. Deposit \n4. Withdraw \n5. Transfer \n6. Display based on account number \n7. Sorting based on balance \n8. Delete account \n9. Exit "
	<< endl;
      cout << "enter your choice: " << endl;
      cin >> choice;
      switch (choice)
	{
	case 1:
	  for (i = 0; i < n; i++)
	    {
	      b[i].create_account ();

	    }
	  break;
	case 2:
	  for (i = 0; i < n; i++)
	    {
	      b[i].display ();
	    }
	  break;
	case 3:
	  cout << "enter the account number: ";
	  cin >> k;
	  b[k].deposit ();
	  break;
	case 4:
	  cout << "enter the account_no:";
	  cin >> k;
	  b[k].withdraw ();
	  break;
	case 5:
	  cout << "enter from account_no:";
	  cin >> k;
	  cout << "enter to account no:";
	  cin >> m;
	  b[k].transfer (b[m]);
	  break;
	case 6:
	  cout << "enter the account number to display the details:";
	  cin >> k;
	  b[k].display ();
	  break;
	case 7:
	  bank::sort (b);
	  break;
	case 8:
	  cout << "enter the account number to delete:";
	  cin >> k;
	  b[k].delete_account ();
	  break;
	default:
	  exit (0);
	}
    }
  return 0;
}

void bank::create_account ()		//create account 
{
  cout << "enter" << i + 1 << " customer's details:" << endl;
  cout << "name: " << endl;
  cin >> name;
  acc_no = generate_accno (i);
  cout << "password: " << endl;
  cin >> password;
  cout << "balance:" << endl;
  cin >> balance;

}

int bank::generate_accno (int i)	//generate unique account numbers 
{
  acc_no = acc_no + i;
  i++;
  return acc_no;
}

void bank::display ()		//display the details of all customers
{
  cout << "customer details: " << endl;
  cout << "name: " << name << endl;
  cout << "account number:" << acc_no << endl;
  cout << "balance: " << balance << endl;
}

void bank::deposit ()		//deposit the amount 
{
  string p;
  int amount;
  cout << "enter the password:";
  cin >> p;
  if (p == password)
    {
      cout << "enter the amount to deposit:";
      cin >> amount;
      balance = balance + amount;
      cout << "balance: " << balance;
    }
  else
    {
      cout << "incorrect password..!!" << endl;

    }

}

void bank::withdraw ()		//withdraw the amount 
{
  string p;
  int amount;
  cout << "enter the password:";
  cin >> p;
  if (p == password)
    {
      cout << "enter the amount to withdraw: ";
      cin >> amount;
      if (amount < balance)
	{
	  balance = balance - amount;
	  cout << "remaining balance: " << balance << endl;

	}
      else
	{
	  cout << "insufficient balance..!" << endl;

	}

    }
  else
    {
      cout << "incorrect password..!!" << endl;
    }

}

void bank::transfer (bank a)		//transfer the amount from one account to another 
{
  int amount;
  string p, q;
  cout << "enter the password for from account: " << endl;
  cin >> p;
  cout << "enter the password for from account: " << endl;
  cin >> q;
  if ((p == password) && (q == a.password))
    {
      cout << "enter the amount to transfer:";
      cin >> amount;
      if (amount < balance)
	{
	  a.balance = a.balance + amount;
	  balance = balance - amount;
	  cout << balance << endl;
	  cout << a.balance << endl;

	}
      else
	{
	  cout << "insufficient balance";
	}
    }
  else
    {
      cout << "invalid password";
    }

}

void bank::sort (bank b[])		// sort the customer details based on balance
{
  int i, j;
  bank temp;
  for (i = 0; i < n; i++)
    {
      for (j = 0; j < n; j++)
	{
	  if (b[i].balance < b[j].balance)
	    {
	      temp = b[i];
	      b[i] = b[j];
	      b[j] = temp;

	    }

	}

    }
  for (i = 0; i < n; i++)
    {
      b[i].display ();
    }
}

void bank::delete_account ()		// delete a specific account 
{
  name = "XXX";
  acc_no = -1;
  balance = -1;

}

Output:

enter the number of customers: 1

  1. Create account
  2. Dispaly all accounts
  3. Deposit
  4. Withdraw
  5. Transfer
  6. Display based on account number
  7. Sorting based on balance
  8. Delete account
  9. Exit
    enter your choice:

If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment