infolink

Friday, 14 March 2014

C++ Banking System Project



Here is a small Bank system using C++. It is not a professional Bank process system. Basically this tutorial is about learning C++. It is a Small C++ course project and C++ basic syntax and structure cover on it.

C++ Banking system features/Methods:

  • Login Authentication - 4 logins with user name & password
  • Account Open
  • Deposit amount
  • Withdraw amount
  • Display all accounts
  • Search account by CNIC No

Brief description about bank System:

First login using 4 different authentications (Username, Password) which is already stored in the string type two dimensional arrays. Then you can open the 10 different accounts after that you can do different transaction through these accounts. You can also search a specific account through CNIC no. and can also display all the records at a same time.

Here is the code of a bank system:

 #include <iostream>
#include <string>
#include <sstream>

using namespace std;

int total_accounts = 10;
string accounts[10][5];
string login_authentication[4][2] = {{"user1","111"},{"user2","222"},{"user3","333"},{"user4","444"}};

void authentication();
void open_account();
void menu();
void deposit_amount();
void all_accounts();
void search_acc();
void withdraw_amount();


int main()
{
   
    char choice;
    do
                {
        system("cls");
        cout<<"1 Log in"<<endl;
                                cout<<"0 Exit"<<endl;
                                cout<<"Choose the desired option: ";
                                cin>>choice;
        switch (choice)
                                {
                                case '1':
                                                authentication();
                                                break;
                                default:
                                                choice='$';
                                                break;
        }
    }while(choice!='$');
                exit(0);
                return 0;
}


////////////////// Functions //////////////////////


///////////////// Menu /////////////////////////////
void menu()
{
     cout<<"1 Open an Account"<<endl;
     cout<<"2 Deposit amount"<<endl;
     cout<<"3 withdraw amount"<<endl;
     cout<<"4 Search All Accounts"<<endl;
     cout<<"5 Search an account using CNIC and display its information"<<endl;
     cout<<"0 Exit"<<endl;
     cout<<"Choose the desired option (1-5): ";
}
////////////////////////////////////////////////////////


//////////////// Log in Authentication Function //////////////
void authentication()
{
     char choice;
     char ch;
     system("cls");
     string username;
     string password;
     int log_in = 0;
     cout<<"User Name: ";
     cin>>username;
     cout<<"Password: ";
     cin>>password;
    
     for(int i=0; i<4; i++)
        {
                if(username == login_authentication[i][0] && password == login_authentication[i][1])
                    {
                            do
                            {
                                 system("cls");
                                 menu();
                                 cin>>choice;
                                 switch (choice)
                                                 {
                                                 case '1':
                                                                open_account();
                                                                system("cls");
                                    menu();
                                                                break;
                                                                 case '2':
                                                                deposit_amount();
                                                                system("cls");
                                    menu();
                                                                break;
                                                                 case '3':
                                                                withdraw_amount();
                                                                system("pause");
                                                                break;
                                                                 case '4':
                                                                all_accounts();
                                                                system("pause");
                                                                break;
                                                                 case '5':
                                                                search_acc();
                                                                break;
                                                 default:
                                                                choice='0';
                                                                break;
                                 }
                                
                                 
                             }while(choice != '0');
                    }
                    else
                        {
                                        cout<<"Invalid Username and Password."<<endl;
                        }
        }
}
//////////////////////////////////////////////////////////////


///////////////// Open an Acciunt ////////////////////////////

void open_account()
{
    
     char ch;
     string acc_num;
     string acc_title;
     string acc_bal;
     string acc_holder_name;
     string acc_holder_cnic;
     int account_num = 1;
         
              if(account_num<=total_accounts)
              {
                  system("cls");
                  menu();
                  for(int j=0; j<total_accounts; j++)
                  {
                          cout<<endl;
                          cout<<endl;
                          cout<<"Account: "<<account_num<<endl;
                          cout<<"Enter Account Number: ";
                          cin>>acc_num;
                          cout<<"Enter Account Title: ";
                          cin>>acc_title;
                          cout<<"Enter Account Balance: ";
                          cin>>acc_bal;
                          cout<<"Enter Account Holder Name: ";
                          cin>>acc_holder_name;
                          cout<<"Enter Account Holder CNIC: ";
                          cin>>acc_holder_cnic;
                         
                          accounts[j][0] = acc_num;
                          accounts[j][1] = acc_title;
                          accounts[j][2] = acc_bal;
                          accounts[j][3] = acc_holder_name;
                          accounts[j][4] = acc_holder_cnic;
                         
                          
                          cout<<"Open another Account.(y/n)?: ";
                          cin>>ch;
                          if(ch != 'n')
                          {
                                account_num++;
                          }
                          else
                          {
                              j=10;
                          }
                  }
              }
             else
             {
                 cout<<"Maximum accounts limit reached."<<endl;
             } 
         
}
///////////////////////////////////////////////////////////


///////////////////// Deposit Amount //////////////////////
void deposit_amount()
{
     int current_bal;
     string acc_no;
     int acc_bal;
     cout<<endl;
     cout<<endl;
     cout<<"Enter Account Number: ";
     cin>>acc_no;
     cout<<"Enter Deposit Amount: ";
     cin>>acc_bal;
     for(int j=0; j<total_accounts; j++)
     {
             if(acc_no == accounts[j][0])
             {
                       string s = accounts[j][2];
                       stringstream ss(s);
                       ss >> current_bal;
                       current_bal = current_bal + acc_bal;
                       stringstream ss1;
                       ss1 << current_bal;
                       accounts[j][2] = ss1.str();
                       //cout<<"Amount Added."<<current_bal<<endl;
                       //system("pause");
             }
     }
}
//////////////////////////////////////////////////////////

///////////////////// Withdraw Amount //////////////////////
void withdraw_amount()
{
     int current_bal;
     string acc_no;
     int acc_bal;
     cout<<endl;
     cout<<endl;
     cout<<"Enter Account Number: ";
     cin>>acc_no;
     cout<<"Enter Deposit Amount: ";
     cin>>acc_bal;
     for(int j=0; j<total_accounts; j++)
     {
             if(acc_no == accounts[j][0])
             {
                       string s = accounts[j][2];
                       stringstream ss(s);
                       ss >> current_bal;
                       current_bal = current_bal - acc_bal;
                       stringstream ss1;
                       ss1 << current_bal;
                       accounts[j][2] = ss1.str();
                       //cout<<"Amount Added."<<current_bal<<endl;
                       //system("pause");
             }
     }
}
//////////////////////////////////////////////////////////


////////////////////////// Search all Accounts /////////////

void all_accounts()
{
     for(int j=0; j<total_accounts; j++)
     {
             cout<<"Account Number: "<<accounts[j][0]<<endl;
             cout<<"Account Title: "<<accounts[j][1]<<endl;
             cout<<"Account Balance: "<<accounts[j][2]<<endl;
             cout<<"Account Holder Name: "<<accounts[j][3]<<endl;
             cout<<"Account Holder CNIC: "<<accounts[j][4]<<endl;
     }
}
/////////////////////////////////////////////////////////////


////////////////// Search Account by CNIC //////////////////
void search_acc()
{
     string acc_h_cnic;
     cout<<"Enter Account Holder CNIC: ";
     cin>>acc_h_cnic;
     cout<<endl;
     cout<<endl;
     for(int j=0; j<total_accounts; j++)
     {
             if(acc_h_cnic == accounts[j][4])
             {
                 cout<<"Account Number: "<<accounts[j][0]<<endl;
                 cout<<"Account Title: "<<accounts[j][1]<<endl;
                 cout<<"Account Balance: "<<accounts[j][2]<<endl;
                 cout<<"Account Holder Name: "<<accounts[j][3]<<endl;
                 cout<<"Account Holder CNIC: "<<accounts[j][4]<<endl;
                 system("pause");
             }
     }
}
////////////////////////////////////////////////////////////

No comments:

Post a Comment