Pages

💡 Now You Can Get your Assignments Sollution here... .💡 100% plagiarism Free Service...💡 Responsibility, punctuality and on-time delivery... 💡 Furnishing you with experts... 💡 experienced in your subject 100% privacy... 💡 helping you with the highest efficiency , professionalism Affordable and budget-friendly costs that do not make a hole in your wallet

Bank System in Cpp

#include<iostream>
#include<fstream>
#include<string>
#include<math.h>
#include<iomanip>
#include<conio.h>
using namespace std;
void loading(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200]);
void menudisplay(int& accounts, int pin[200], int acnum[200], int funds[200], char acname[200][20], char type[200]);    //prototype for menu function
void createaccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200]);    //prototype for creat account function
void depositfunds(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20],int pins[200]);                  //prototype for deposit funnds function
void withdrawfunds(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pins[200]);                 //prototype for withdrawing funds function
void checkbalance(int& accounts, int acnum[200], int funds[200]);                                                         //prototype for checking balance of indivisual account function
void allaccountholders(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20]);                  //prototype for to see all account holders list function
void closeaccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20],int pins[200]);                      //prototype for closing an account function
void modifyaccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20],int pins[200]);                     //prototype for modifying an account function
void useraccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200]);         //prototype for user can see his account details function
void modify2(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200]);
//***************************************************************
//   the main function of program
//****************************************************************

int main()
{
int pin[200];
char choice;
int accounts = 0;
int acnum[200], funds[200]; char acname[200][20]; char type[200];
int loopvar = 1;
ifstream indata;
indata.open("accounts.txt");
indata >> accounts;
indata.close();
system("color b1");
char  x;
cout << "Do you want to start from 0 accounts , press y for yes .n for no" << endl;
cin >> x;
if (x == 'n' || x == 'N')
{
loading(accounts, acnum, funds, type, acname, pin);
}
if (x == 'y' || x == 'Y')
{
accounts = 0;
}
for (int p = 1; p;)       //for loop to check admin login ,user login ,exit ,,,other wise continue
{
cout << "     .          .  .....  .         ..         ..      .    .      .....\n      .   .    .   .      .       .    .     .    .    ..  ..      .\n       . .  . .    .....  .       .         .      .   . .. .      .....\n        .    .     .      .       .    .     .    .    .    .      .\n                   .....  .....     ..         ..      .    .      ....." << endl;
cin.get();         //a samll function which gives the next operation after pressing "enter"
cout << "\n\n\n                 Admin Login ...press A\n                 User Login .....press U\n                 For Exit press E" << endl;
cin >> choice;
if (choice == 'a' || choice == 'A')
{
do
{
char ch;
int count = 0;
char password[6] = "A^0g0";
string pass;
cout << "Enter the password" << endl;
ch = _getch();           //      this
for (; count<5; count++)     //        will
{                           //             produce
pass.push_back(ch);       //                  stars
cout << '*';           //                         istead of
ch = _getch();            //                               characters of password
}
if (pass == password)
{
loopvar = 0;
menudisplay(accounts, pin, acnum, funds, acname, type);       // calling menu function for admin only
system("CLS");
}
} while (loopvar);    // do_while loop for admin password check
}
if (choice == 'u' || choice == 'U')
{
useraccount(accounts, acnum, funds, type, acname, pin);    //calling user detail function for user only
system("CLS");
}
if (choice == 'E' || choice == 'e')
{
cout << "Thanks for Using Bank Account System" << endl;
p = 0;
}
}
}
//***************************************************************
//     the menu of program
//****************************************************************

void menudisplay(int& accounts, int pin[200], int acnum[200], int funds[200], char acname[200][20], char type[200])
{

int choice = 0;
cout << "*                *                *\n***              ***              ***\n*****            *****            *****\n*******          *******          *******\n*****            *****            *****\n***              ***              ***\n*                *                *" << endl;
for (choice; choice != 8;) //for loop for choice of functions in main menu
{
cout << "\n                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
cout << "\n                 Press 1 to create new account" << endl;
cout << "\n                 Press 2 to deposit funds " << endl;
cout << "\n                 Press 3 to withdraw funds" << endl;
cout << "\n                 Press 4 to check balance" << endl;
cout << "\n                 Press 5 to view all account holders" << endl;
cout << "\n                 Press 6 to close an account" << endl;
cout << "\n                 Press 7 to modify an account" << endl;
cout << "\n                 Press 8 to exit program" << endl;
cout << "\n                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
cin >> choice;
switch (choice) // switch to connect with required function
{
case 1:
createaccount(accounts, acnum, funds, type, acname, pin);   //calling create account function
system("CLS");
break;
case 2:
depositfunds(accounts, acnum, funds, type, acname,pin);           //calling deposit funds function
system("CLS");
break;
case 3:
withdrawfunds(accounts, acnum, funds, type, acname,pin);        //calling withdraw funds function
system("CLS");
break;
case 4:
checkbalance(accounts, acnum, funds);                        //calling function to check balance of indivisual accounts
system("CLS");
break;
case 5:
allaccountholders(accounts, acnum, funds, type, acname);    //calling all account holders list function
system("CLS");
break;
case 6:
closeaccount(accounts, acnum, funds, type, acname,pin);           //calling close an account function
system("CLS");
break;
case 7:
modifyaccount(accounts, acnum, funds, type, acname,pin);         //calling function to modify an account
system("CLS");
break;
case 8:                                                        //8 for exit
system("CLS");
break;
default:
break;
}
}
}
//***************************************************************
//              create account
//****************************************************************

void createaccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200])
{
ofstream outdata;
if (accounts == 0)
{
for (int i = 0; i < 200; i++)       // for loop filling full 2d array with spaces
{
for (int j = 0; j < 20; j++)
{
acname[i][j] = ' ';
}
}
}
if (accounts >199)
{
cout << " you cant save more accounts " << endl; cin.get(); cin.get();
menudisplay(accounts, pin, acnum, funds, acname, type);       // calling menu function for not because accounts are full
}
for (int k = 1; k;)
{
cout << "Account 'number' for User number " << accounts + 1 << endl;
cin >> acnum[accounts];
if (accounts > 0)                                  // if condition and then for loops and then some if conditions to check if account number alreday present
{
for (int f = 0; f < accounts; f++)
{
if (acnum[accounts] == acnum[f])
{
cout << "\nAccount no. Already Present\n" << endl;
k = 1;
break;
}
else
{
k = 0;
}
}
}
else k = 0;
}

if (accounts == 0)
{
outdata.open("acnum.txt");
}
else
outdata.open("acnum.txt", std::fstream::app);
outdata << acnum[accounts] << endl;
outdata.close();
for (int k = 1; k;)
{
cout << "Account 'Name' for User number " << accounts + 1 << endl;
cin >> acname[accounts];
//cin.ignore();
//cin.getline(acname[accounts], 200);
if (accounts > 0)                           // if condition and then for loops and then some if conditions to check if account name alreday present
{
for (int f = 0; f < accounts; f++)
{
if ((strcmp(acname[accounts], acname[f]) == 0))
{
cout << "\nAccount Name Already Present\n" << endl;
k = 1;

}
else
{
k = 0;
}
}
}
else k = 0;
}
if (accounts == 0)
{
outdata.open("acname.txt");
}
else
{
outdata.open("acname.txt", std::fstream::app);
}
outdata << acname[accounts] << endl;
outdata.close();
cout << "Enter Account type < 's' for Saving and 'c' for Current" << endl;
cin >> type[accounts];
if (accounts == 0)
outdata.open("actype.txt");
else
outdata.open("actype.txt", std::fstream::app);
outdata << type[accounts] << endl;
outdata.close();
int h = 1;            //a simple variable
do
{
cout << "Enter the initial amount <500 or more for saving and 1000 or more for current>" << endl;
cin >> funds[accounts];
if (type[accounts] == 's' || type[accounts] == 'S')           //if statement to check account type and then its funds
{
if (funds[accounts] >= 500 && funds[accounts] < 1000)
{
h = 0;
}
}
if (type[accounts] == 'c' || type[accounts] == 'C')           //if statement to check account type and then its funds
{
if (funds[accounts] >= 1000)
{
h = 0;
}
}
}
while (h);
///////////////////////////////////////////
if (accounts == 0)
{
outdata.open("funds.txt");
}
else
outdata.open("funds.txt", std::fstream::app);
outdata << funds[accounts] << endl;
outdata.close();
//////////////////////////////////////////
cout << "Enter the pin code for current" << endl;
cin >> pin[accounts];
if (accounts == 0)
{
outdata.open("pins.txt");
}
else
{
outdata.open("pins.txt", std::fstream::app);
}
outdata << pin[accounts] << endl;
outdata.close();
cout << "Account succesfully created" << endl;
outdata.open("accounts.txt");
accounts++;
outdata << accounts;
outdata.close();
system("CLS");
}
//***************************************************************
//        deposit amount
//****************************************************************

void depositfunds(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20],int pins[200])
{
int acnumd, fundd = 0, counter = 0;
cout << "Enter the account number" << endl;
cin >> acnumd;
for (int i = 0; i < accounts; i++)
{
if (acnum[i] == acnumd)
{

cout << "Account number :" << acnum[i] << endl;
cout << "Account name :" << acname[i] << endl;
cout << "Account type :" << type[i] << endl;
cout << "To deposit amount" << endl;
cout << "                  Enter the amount deposited " << endl;
cin >> fundd;             //entering the amount to add
funds[i] = funds[i] + fundd;
break;
}counter++;
}
cout << "Record updated" << endl; cin.get(); cin.get();
if (counter == accounts){
cout << "Record not found" << endl;              //if statement to check if account not present
}
modify2(accounts, acnum, funds, type, acname, pins);
cin.get(); cin.get();               //a samll function which gives the next operation after pressing "enter"
}
//***************************************************************
//     withdraw funds
//****************************************************************

void withdrawfunds(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20],int pins[200])
{
int acnumd, fundd = 0, counter = 0;
cout << "Enter the account number" << endl;
cin >> acnumd;
for (int i = 0; i < accounts; i++)            //for loop to check the account number and then if present or not
{
if (acnum[i] == acnumd)
{
cout << "Account number :" << acnum[i] << endl;
cout << "Account name :" << acname[i] << endl;
cout << "To withdraw amount" << endl;
cout << "                  Enter the amount withdrawn " << endl;
cin >> fundd;
funds[i] = funds[i] - fundd;
break;
}counter++;
}
cout << "Record updated\n\n" << endl; cin.get(); cin.get();
if (counter == accounts){
cout << "Recrd not found" << endl; //if statement to check if account not present
cin.get(); cin.get();                 //a samll function which gives the next operation after pressing "enter"
}
modify2(accounts, acnum, funds, type, acname, pins);
}
//***************************************************************
//     check balance
//****************************************************************

void checkbalance(int& accounts, int acnum[200], int funds[200])
{
int acnumc;
cout << "Enter the Account Number" << endl;
cin >> acnumc;
for (int i = 0; i < accounts; i++)      //for loop to check the account number and then if present or not
{
if (acnum[i] == acnumc)
{
cout << "Funds are:  " << funds[i];
}
}
cin.get(); cin.get();                       //a samll function which gives the next operation after pressing "enter"
}

//***************************************************************
//     all acount holders
//****************************************************************

void allaccountholders(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20])
{
cout << "\n\n\t\tACCOUNT HOLDER LIST\n\n";
cout << "====================================================\n";
cout << "A/C no.      Name           Type        Balance\n";
cout << "====================================================\n";
for (int i = 0; i < accounts; i++)
{
cout << acnum[i] << "      ";
for (int j = 0; j < 20; j++)
{
cout << acname[i][j];
}cout << "   " << type[i] << "        " << funds[i] << endl;
}
cin.get(); cin.get();                       //a samll function which gives the next operation after pressing "enter"
}
//***************************************************************
//     closing account
//****************************************************************

void closeaccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20],int pins[200])
{
int acnumc;
cout << "Enter the Account Number" << endl;
cin >> acnumc;
accounts--;
for (int i = 0; i < accounts; i++)   //for loop to check the account number and then if present or not
{
if (acnum[i] == acnumc)
{
for (int k = i; k < accounts; k++)
{
acnum[k] = acnum[k+1];    //it will replace the account number with zeros
funds[k] = funds[k+1];     //it will replace the account funds with zeros
type[k] = type[k+1];//it will replace the account type with space
pins[k] = pins[k+1];
for (int j = 0; j < 20; j++)
{
acname[k][j] = acname[k+1][j];      //it will replace the account name with spaces
}
}
}
}
ofstream outdata;
outdata.open("accounts.txt");
outdata << accounts;
outdata.close();
modify2(accounts, acnum, funds, type, acname, pins);
cin.get(); cin.get();                //a samll function which gives the next operation after pressing "enter"
}
//***************************************************************
//     modify account
//****************************************************************

void modifyaccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20],int pins[200])
{
int choice, acnumu;
cout << "Enter Your Account Number" << endl;
cin >> acnumu;
for (int k = 0; k < accounts; k++)   //for loop to check the account number and then if present or not
{
if (acnumu == acnum[k])
{
cout << "====================================================\n";
cout << "A/C no.      Name           Type        Balance\n";
cout << "====================================================\n";
cout << acnum[k] << "      ";
for (int j = 0; j < 20; j++)
{
cout << acname[k][j];
}cout << "   " << type[k] << "        " << funds[k] << endl;
cout << "                 what do you want in modification function" << endl;
cout << "                 press 1 to change the name of account" << endl;
cout << "                 press 2 to change the type of account" << endl;
cin >> choice;
switch (choice)           //switch statement to go to required case
{
case 1:
for (int j = 0; j < 20; j++) // for loop filling full 2d array with spaces
{
acname[k][j] = ' ';
}
cout << "enter new name" << endl;
cin >> acname[k];
break;
case 2:
cout << "enter new type" << endl;
cin >> type[k];
break;
default:
break;
}
}
}
modify2(accounts, acnum, funds, type, acname, pins);
cin.get(); cin.get();              //a samll function which gives the next operation after pressing "enter"
}
//***************************************************************
//     user can see his account
//****************************************************************

void useraccount(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200])
{
int acnumu, pinu;
cout << "enter your account number" << endl;
cin >> acnumu;
for (int k = 0; k < accounts; k++)   //for loop to check the account number and then if present or not
{
if (acnumu == acnum[k])
{
cout << "enter the pin code of your account" << endl;
cin >> pinu;
if (pinu == pin[k])    //if statement will match pin of that account which entered pin
{
cout << "====================================================\n";
cout << "a/c no.      name           type        balance\n";
cout << "====================================================\n";
cout << acnum[k] << "      ";
for (int j = 0; j < 20; j++)       // for loop to generate the name
{
cout << acname[k][j];
}cout << "   " << type[k] << "        " << funds[k] << endl;
}
}
}
cin.get(); cin.get();      
//a samll function which gives the next operation after pressing "enter"
}
//***************************************************************
//     loading from files
//****************************************************************

void loading(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200])
{
  string s;
ifstream indata;
indata.open("acnum.txt");
for (int k = 0; k < accounts; k++)
{
indata>>acnum[k];
}
indata.close();
indata.open("acname.txt");
for (int k = 0; k < accounts; k++)
{
  indata >> acname[k];
}
indata.close();
indata.open("pins.txt");
for (int k = 0; k < accounts; k++)
{
indata >> pin[k];

}
indata.close();
indata.open("funds.txt");
for (int k = 0; k < accounts; k++)
{
indata >> funds[k];

}
indata.close();
indata.open("actype.txt");
for (int k = 0; k < accounts; k++)
{
indata >> type[k];

}
indata.close();
}
void modify2(int& accounts, int acnum[200], int funds[200], char type[200], char acname[200][20], int pin[200])
{
ofstream outdata;
outdata.open("acname.txt");
for (int k = 0; k < accounts; k++)
{
outdata << acname[k] << endl;
}
outdata.close();
outdata.open("acnum.txt");
for (int k = 0; k < accounts; k++)
{
outdata << acnum[k] << endl;
}
outdata.close();
outdata.open("actype.txt");
for (int k = 0; k < accounts; k++)
{
outdata << type[k] << endl;
}
outdata.close();
outdata.open("funds.txt");
for (int k = 0; k < accounts; k++)
{
outdata << funds[k] << endl;
}
outdata.close();
outdata.open("pins.txt");
for (int k = 0; k < accounts; k++)
{
outdata << pin[k] << endl;
}
outdata.close();


}

No comments: