n0va_sa

Banking_system_modle

Apr 28th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.48 KB | None | 0 0
  1. //Rothschild Bank//
  2. #include <iostream>
  3. #include <string>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. class Account {
  8. private:
  9.     double account_balance; char account_type; int account_number;
  10. public:
  11.     Account() {
  12.         account_balance = 0.00;
  13.         account_type = 's';
  14.         account_number = 0;
  15.     }
  16.     double make_depo(double money) {
  17.         account_balance += money;
  18.         return account_balance;
  19.     }
  20.     double make_withdrawl(double money) {
  21.         if (account_type == 'c')
  22.             account_balance -= money;
  23.         else {
  24.             if (money >= 10000) {
  25.                 cout << "Your account is a Standard Account, you can't take more that $10000\n";
  26.                 cout << "Making Your Witdrawl Limit to $10000\n";
  27.                 money = 10000;
  28.             }
  29.             account_balance -= money;
  30.         }
  31.         return account_balance;
  32.     }
  33.     double get_account_balance() {
  34.         return account_balance;
  35.     }
  36.     string get_account_type() {
  37.         if (account_type == 'c') return "Commercial Account";
  38.         return "Standard Account";
  39.     }
  40.     int get_account_number() {
  41.         return account_number;
  42.     }
  43.     double setCustomerAccount(double depo_money,char acc_type,int ac_number) {
  44.         account_balance = depo_money;
  45.         account_type = acc_type;
  46.         account_number = ac_number;
  47.         return account_balance;
  48.     }
  49. };
  50. class Customer {
  51. private:
  52.     Account customer_account; string account_holder;
  53. public:
  54.     void make_bank_account(int* reserveAccount,int* sizeofArr) {
  55.         char temp; int ac_num,takenFlag=0, flag = 0;
  56.         cout << "Enter Account Holder's Name: "; cin >> account_holder;
  57.         cout << "[c]Commercial Account or [s]Standard Account: "; cin >> temp;
  58.         while(flag == 0){
  59.             cout << "Enter Your Custom Account Number: "; cin >> ac_num;
  60.             takenFlag=0;
  61.             for (int i = 0;i < *sizeofArr;i++){
  62.                  if (reserveAccount[i] == ac_num){
  63.                     cout << "Account Already Taken\n\n";
  64.                     takenFlag = 1;
  65.                     break;
  66.                 }
  67.             }
  68.             if(takenFlag == 1){
  69.                 flag = 0;
  70.             } else{
  71.                 flag = 1;
  72.             }
  73.         }
  74.         cout << customer_account.setCustomerAccount(100.00, temp, ac_num) << "$ Your Current Account Balance" << endl << endl;
  75.  
  76.         reserveAccount[(*sizeofArr)++] = ac_num;
  77.     }
  78.     void show_account_details() {
  79.         cout << "\t\tA.C.C.O.U.N.T   H.O.L.D.E.R.S   D.E.T.A.I.L.S " << endl << endl;
  80.         cout << "Account Holder Name: " << account_holder << endl;
  81.         cout << "Account Balance: " << customer_account.get_account_balance() << endl;
  82.         cout << "Account Type is: " << customer_account.get_account_type() << endl;
  83.         cout << "Account Number Assigned: " << customer_account.get_account_number() << endl;
  84.     }
  85.     void depositMoney() {
  86.         cout << "\t\tD.E.P.O.S.I.T MONEY" << endl << endl;
  87.         double money;
  88.         cout << "Enter The Amount: "; cin >> money;
  89.         cout << "ACCOUNT BALANCE: " << customer_account.make_depo(money) << endl;
  90.     }
  91.     void withdrawlMoney() {
  92.         cout << "\t\tW.I.T.H.D.R.A.W.L MONEY" << endl << endl;
  93.         double money;
  94.         cout << "Enter The Amount: "; cin >> money;
  95.         cout << customer_account.make_withdrawl(money) <<endl;
  96.     }
  97.     int get_Account_number() {
  98.         return customer_account.get_account_number();
  99.     }
  100.     void send_money(double money) {
  101.         customer_account.make_withdrawl(money);
  102.     }
  103.     void recieve_money(double money) {
  104.         customer_account.make_depo(money);
  105.     }
  106. };
  107. class ROTHSCHILDBANKINGSYSTEM {
  108.     Customer cus[20]; int totalCustomer = 0;int sizeofArr=0;
  109.     int* reserveAccount = (int*)calloc(10,sizeof(int));
  110. public:
  111.     void reserveArr(){
  112.         for (int i =0 ;i<sizeofArr;i++){
  113.             cout << reserveAccount[i] << "   ";
  114.         }
  115.         cout << endl;
  116.     }
  117.     void set_customer(int num_of_new_customer) {
  118.         for (num_of_new_customer += totalCustomer; totalCustomer < num_of_new_customer;totalCustomer++) {
  119.                 reserveArr();
  120.             cus[totalCustomer].make_bank_account(reserveAccount,&sizeofArr);
  121.             cus[totalCustomer].depositMoney();
  122.             cus[totalCustomer].show_account_details();
  123.                 reserveArr();
  124.             system("pause");
  125.             system("cls");
  126.         }
  127.     }
  128.     void transferMoney(int fromAccount, int toAccount, double money) {
  129.         Customer to_cus, from_cus; int from_pos = -1, to_pos = -1;
  130.         for (int i = 0; i < 20; i++) {
  131.             if (from_pos != -1 && to_pos != -1) break;
  132.             if (cus[i].get_Account_number() == fromAccount) {
  133.                 from_cus = cus[i]; from_pos = i;
  134.             }
  135.             if (cus[i].get_Account_number() == toAccount) {
  136.                 to_cus = cus[i]; to_pos = i;
  137.             }
  138.         }
  139.         if (from_pos == -1 || to_pos == -1) {
  140.             cout << "ERROR: Maybe one or both the Account Number is Wrong!!!\n\n";
  141.             return;
  142.         }
  143.         from_cus.send_money(money); // from A money is Deducting
  144.         to_cus.recieve_money(money); // to B Money is Incrementing
  145.         cus[from_pos] = from_cus;
  146.         cus[to_pos] = to_cus;
  147.         //==============Showing Remaining Balance==============//
  148.         cout << "\nSENDER\n";
  149.         cus[from_pos].show_account_details();
  150.         cout << "\nRECIVER\n";
  151.         cus[to_pos].show_account_details();
  152.     }
  153.     void show_customer_details(int account_number) {
  154.         for (auto i : cus) {
  155.             if (i.get_Account_number() == account_number) {
  156.                 i.show_account_details();
  157.                 return;
  158.             }
  159.         }
  160.         cout << "No Such Customer Exists\n\n";
  161.     }
  162. };
  163.  
  164.  
  165. //=====================Main==========================//
  166.  
  167. #include "banking.h"
  168. #include <fstream>
  169. void add_new_bank_customers();
  170. void getCustomerDetails();
  171. void transfer_money();
  172. void update_database();
  173. void view() {
  174.     system("pause");
  175.     system("cls");
  176. }
  177. ROTHSCHILDBANKINGSYSTEM rchild;
  178. int main() {
  179.     int choice; int flag = 0;
  180.     while (true) {
  181.         cout << "1. Add Customer\n2.Get Customer Details\n3.Transfer Money\n4.Update Database\n:~# ";
  182.         cin >> choice;
  183.         switch (choice)
  184.         {
  185.         case 1:
  186.             add_new_bank_customers(); break;
  187.         case 2:
  188.             getCustomerDetails(); view(); break;
  189.         case 3:
  190.             transfer_money(); view(); break;
  191.         case 4:
  192.             update_database(); break;
  193.         default:
  194.             flag = 1;
  195.             break;
  196.         }
  197.         if (flag == 1) { break; }
  198.     }
  199.     return 0;
  200. }
  201. void transfer_money() {
  202.     int send_ac_num, rec_ac_num; double money;
  203.     cout << "Enter Senders Account Number: "; cin >> send_ac_num;
  204.     cout << "Enter Receivers Account Number: "; cin >> rec_ac_num;
  205.     cout << "Enter Your Amount Money: "; cin >> money;
  206.     rchild.transferMoney(send_ac_num,rec_ac_num,money);
  207. }
  208. void add_new_bank_customers() {
  209.     int total;
  210.     cout << "How Many Customer Account Are to be open ?: "; cin >> total;
  211.     rchild.set_customer(total);
  212. }
  213.  
  214. void getCustomerDetails() {
  215.     int account_num;
  216.     cout << "Enter The Account Number: "; cin >> account_num;
  217.     rchild.show_customer_details(account_num);
  218. }
  219.  
  220. void update_database() {
  221.     ofstream rchild_db;
  222.     rchild_db.open("bankDatabase.bin",ios::out|ios::binary);
  223.     if (rchild_db.is_open()) {
  224.         cout << "updating relational database...\n";
  225.         rchild_db.write((char*)(&rchild), sizeof(ROTHSCHILDBANKINGSYSTEM));
  226.     }
  227.     else {
  228.         cout << "fail to open database...\n"; return;
  229.     }
  230.     rchild_db.close();
  231. }
Add Comment
Please, Sign In to add comment