Advertisement
Brandan

Untitled

Feb 19th, 2014
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.76 KB | None | 0 0
  1. // Project: Basic Banking Software Database
  2. // Name: Brandan Tyler Lasley
  3. // Date: 1/30/2014 18:57
  4.  
  5. // should this be an economy where money can't be created or destroyed? Maybe a default cash? like a real bank?
  6.  
  7. // This will be based on a level system from 0 - 2
  8. // 0 Customer
  9. // 1 Employee
  10. // 2 Boss (root?)
  11.  
  12. // ====== CUSTOMER ======
  13. // Balance
  14. // Depost
  15. // Withdraw
  16. // Transfer
  17. // Total Cash (optional, A place to withdrawl money, employee or bank shouldn't beable to NSA spy on the customer?)
  18.  
  19. // ====== EMPLOYEE ======
  20. // Everything above
  21. // Add customer (account)
  22. // Delete customer (account)
  23. // Search records using "Name" using Swquential search
  24.  
  25. // ====== BOSS ======
  26. // Everything in the bank teller and customer
  27. // List total number of employees in bank
  28. // List Ttoal amount of money in the bank
  29. // Total deposits in a day
  30. // total withdrawls in a day
  31. // Abillity to see detailed log of all transactions
  32. // Sort databade (optional)
  33. // Create money (optional)
  34.  
  35. // Remember to declare constants or a varible to control ALL ARRAYS!
  36.  
  37. // Completed (0/16) levels (0/3)
  38.  
  39. // Todo:
  40. // Customer
  41. // Employee
  42. // Boss
  43.  
  44. // Know Issues & Limiatations:
  45. // Max 2000 customers
  46. // If you use the illegal char '◦' anywhere in the program it will corrupt the database, I may fix this.
  47. // I have no idea how a credit card, savings, or 'instant access' works. So those wasn't added.
  48.  
  49. // Before I started this project, I wrote an entire program in VB.NET using structs of arrays and classes
  50. // that scrapes live 911 call data off WCCCA's Civic data. To see if I knew it well enough to write this program.
  51. // It was quite successful. It was orignally written in PHP, but thanks to structs and classes (php has classes I just dont use them often) its more easier
  52. // to manage and my webhost isn't yelling at me about memory useage.
  53.  
  54. // It now runs the twitter accounts @Washco_firemed, @clackco_firemed, @pdxlifeflight, and @CADAlerts. I was self thought programming when I was very young and I missed a lot of stuff
  55. // that would've made my life eaiser.
  56.  
  57. // Thanks for forcing me to learn structs, also enums were quite intesting.
  58.  
  59. #include <iostream>
  60. #include <string>
  61. #include <fstream>
  62. #include<stdio.h>
  63. #include<conio.h>
  64. #include "BBSD.h"
  65.  
  66. using namespace std;
  67.  
  68. char db_char = '◦';
  69.  
  70. enum AccountType {
  71.     unknown = -1, Checking, Savings, CreditCard, InstantAccess
  72. };
  73.  
  74. enum Permissions {
  75.     Customer, Employee, Root
  76. };
  77.  
  78. struct Account {
  79.     // Login Info
  80.     string username;
  81.     string password;
  82.  
  83.     int account;
  84.     string firstName;
  85.     string lastName;
  86.     AccountType type;
  87.     Permissions Permissions;
  88.     float money; // Money is like debit
  89.     float cash;  // Cash is what the 'customer' has on hand. hypothetical.
  90. };
  91.  
  92. struct Log {
  93.     int account;
  94.     string timestamp;
  95.     string method;
  96.     int successful;
  97.     float amount;
  98. };
  99.  
  100.  
  101. class customer  {
  102.     // ====== CUSTOMER ======
  103.     // Balance
  104.     // Depost
  105.     // Withdraw (and transfer)
  106.     // Total Cash (optional, A place to withdrawl money, employee or bank shouldn't beable to NSA spy on the customer?)
  107.  
  108. public:
  109.     void balance(int customerid, Account accounts[], int size) { // <B>
  110.         for (int i = 0; i = size - 1; i++) {
  111.             if (customerid == accounts[i].account) {
  112.                 cout << "Your current balance: " << accounts[i].money << endl;
  113.             }
  114.         }
  115.         cout << "Could not find account!" << endl;
  116.     }
  117.  
  118.     bool depost(int customerid, double amount, Account accounts[], int size) { // <D>
  119.         for (int i = 0; i = size - 1; i++) {
  120.             if (customerid == accounts[i].account) {
  121.                 if (amount > accounts[i].cash) {
  122.                     cout << "You do not have enough cash to make this deposit!" << endl;
  123.                     return false;
  124.                 }
  125.                 else {
  126.                     accounts[i].money = accounts[i].money + amount;
  127.                     accounts[i].cash = accounts[i].cash - amount;
  128.                     cout << "Deposit Successful! Amount: " << amount << endl;
  129.                     return true;
  130.                 }
  131.             }
  132.         }
  133.         cout << "Could not find account!" << endl;
  134.         return false;
  135.     }
  136.  
  137.     bool withdraw(int customerid, double amount, Account accounts[], int size) { // <W>
  138.         for (int i = 0; i = size - 1; i++) {
  139.             if (customerid == accounts[i].account) {
  140.                 if (amount > accounts[i].money) {
  141.                     cout << "You do not have enough money to make this withdrawl!" << endl;
  142.                     return false;
  143.                 } else {
  144.                     accounts[i].money = accounts[i].money - amount;
  145.                     accounts[i].cash = accounts[i].cash + amount;
  146.                     cout << "Withdraw Successful! Amount: " << amount << endl;
  147.                     return true;
  148.                 }
  149.             }
  150.         }
  151.         cout << "Could not find account!" << endl;
  152.         return false;
  153.     }
  154.  
  155.  
  156.     // I dont know enough about banks to impliment it the way you want it... is a Checkings/Savings account on a completely
  157.     // different account or is it the same account just with a struct and can a credit card go into the negitives!??
  158.  
  159.     // ATMs dont allow you to transfer funds anyways, atleast not any that I've used.
  160.     // This function will simpily transfer it from one account to the other, this is a debit type system because i've only used a
  161.     // debit card and have no idea how anything else works. No negatives, no debt.
  162.  
  163.     // I do enjoy how you leave most of the project up to your imagination and research though.
  164.     bool transfer(int customerid, double amount, int accountid, Account accounts[], int size) { // <W>
  165.             int myaccount = -1;
  166.             // Find my account number (index).
  167.             for (int i = 0; i = size - 1; i++) {
  168.                 if (customerid == accounts[i].account) {
  169.                     myaccount = i;
  170.                 }
  171.             }
  172.  
  173.             if (myaccount == -1) {
  174.                 return false;
  175.             }
  176.  
  177.             // Find the account number of the transfer person.
  178.             for (int i = 0; i = size - 1; i++) {
  179.                 if (accountid == accounts[i].account) {
  180.                     if (accounts[myaccount].money < amount) { // < means less than, abit dyslexic when it comes to <> so I get it wrong, its the other way.
  181.                         return false;
  182.                     } else {
  183.                         accounts[myaccount].money = accounts[myaccount].money - amount;
  184.                         accounts[i].money = accounts[i].money + amount;
  185.                         cout << "Transfer Successful! Amount: " << amount << endl;
  186.                         return true;
  187.                     }
  188.                 }
  189.             }
  190.         cout << "Could not find account!" << endl;
  191.         return true;
  192.     }
  193.  
  194.     void customercash(int customerid, Account accounts[], int size) { // <CC>
  195.         for (int i = 0; i = size - 1; i++) {
  196.             if (accounts[i].account == customerid) {
  197.                 cout << "Your current cash is: " << accounts[i].cash << endl;
  198.                 break;
  199.             }
  200.         }
  201.     }
  202. };
  203. class empolyee {
  204.     // ====== EMPLOYEE ======
  205.     // Everything above
  206.     // Add customer (account)
  207.     // Delete customer (account)
  208.     // Search records using "Name" using Swquential search
  209.  
  210. public:
  211.     bool addCustomer(int customerid, Account accounts[], int size) { //AC
  212.        
  213.         for (int i = 0; i = size - 1; i++) {
  214.             if (accounts[i].account == NULL) {
  215.                 // Add new account! (username, password, other stuff; needs more function values!)
  216.                 return true;
  217.                 break;
  218.             }
  219.         }
  220.  
  221.         return false;
  222.     }
  223.  
  224.     bool delCustomer(int customerid, Account accounts[], int size) { // DC
  225.         for (int i = 0; i = size - 1; i++) {
  226.             if (accounts[i].account == customerid) {
  227.                 // Add new account! (username, password, other stuff; needs more function values!)
  228.                 return true;
  229.                 break;
  230.             }
  231.         }
  232.  
  233.         return false;
  234.     }
  235.  
  236.     std::string search(std::string customername, Account accounts[], int size) { // search
  237.         for (int i = 0; i = size - 1; i++) {
  238.             if (accounts[i].firstName == customername) {
  239.                 // Print out customer infomation!
  240.             }
  241.         }
  242.     }
  243. };
  244. class root {
  245.     // ====== BOSS ======
  246.     // Everything in the bank teller and customer
  247.     // List total number of employees in bank
  248.     // List total amount of money in the bank
  249.     // Total deposits in a day
  250.     // total withdrawls in a day
  251.     // Abillity to see detailed log of all transactions
  252.     // Sort databade (optional)
  253.     // Create money (optional)
  254.     // Reload DB (optional)
  255.     // Save DB (optional)
  256.  
  257. public:
  258.     string listEmployees(Account accounts[], int size) {
  259.         return "None";
  260.     }
  261.  
  262.     void totalDeposits() { // <--- Needs work
  263.  
  264.     }
  265.  
  266.     void totalWithdrawl() { // <--- Needs Work
  267.  
  268.     }
  269.  
  270.     void viewLog() { // <<----- Needs work
  271.  
  272.     }
  273.  
  274.     bool reloadDatabase(Account accounts[], int size) {
  275.         return true;
  276.     }
  277.  
  278.     bool saveDatabase(Account accounts[], int size) {
  279.         return true;
  280.     }
  281.  
  282.     bool createMoney(double ammount, int customerid, Account accounts[], int size) {
  283.         string input;
  284.         cout << "Are you sure you want to 'Create Money', This could very well crash our economy" << endl << "Answer (Y/N): ";
  285.         cin >> input;
  286.  
  287.         if ((input == "Y" || input == "y")) {
  288.  
  289.         }
  290.         else {
  291.             return false;
  292.         }
  293.  
  294.     }
  295.  
  296. };
  297. class security {
  298.  
  299.     // This will be based on a level system from 0 - 2
  300.     // 0 Customer
  301.     // 1 Employee
  302.     // 2 Boss (root?)
  303.  
  304. public:
  305.  
  306.     bool login(string username, string password, Account accounts[], int size) {
  307.         for (int i = 0; i = size - 1; i++) {
  308.             if ((username == accounts[i].username) && (username == accounts[i].password)) {
  309.                 return true;
  310.             }
  311.         }
  312.         return false;
  313.     }
  314.  
  315.     int getAccount(string username, Account accounts[], int size) {
  316.         for (int i = 0; i = size - 1; i++) {
  317.             if ((username == accounts[i].username)) {
  318.                 return accounts[i].account;
  319.             }
  320.         }
  321.     }
  322.  
  323.     string permissionname(int permissionlvl, Account accounts[], int size) {
  324.         if (permissionlvl == Permissions::Customer) {
  325.             return "Customer";
  326.         }
  327.         else if (permissionlvl == Permissions::Employee) {
  328.             return "Employee";
  329.         }
  330.         else if (permissionlvl == Permissions::Root) {
  331.             return "Root/Administrator";
  332.         } else {
  333.             return "Malicious User";
  334.         }
  335.     }
  336. };
  337.  
  338. // How do we do the account # thing for the current user logged in?
  339. // Do we just load the info at start?
  340. // Should we also ask if they want to deposit to another user?
  341. // Transer?
  342.  
  343. int main() {
  344.  
  345.     // Class Declarisons
  346.     security access;
  347.     customer customer;
  348.     empolyee empolyee;
  349.     root root;
  350.  
  351.  
  352.    
  353.     // Array size 2000, MAX Customers.
  354.      const int ARRAY_SIZE = 2000;
  355.  
  356.     // Username & Password, this is a secure system.
  357.     string username;
  358.     string password;
  359.  
  360.     // Declare Struct
  361.     Account accounts[ARRAY_SIZE];
  362.  
  363.     customer.withdraw(0, 0, accounts, ARRAY_SIZE);
  364.  
  365.     int id = access.getAccount(username, accounts, ARRAY_SIZE); // Gets the ID, faster to seek than searching strings, good pratice for MySQL also.
  366.  
  367.     cout << "Welcome to Brandans Banking System!" << endl;
  368.     cout << "Username: ";
  369.     cin >> username;          // Usernames cannot contains spaces
  370.     getchar();               // Fix annoying auto input from enter.
  371.     cout << "Password: ";
  372.     getline(cin, password);// It would be stupid to restirct passwords though.
  373.  
  374.     // ==== Login ====
  375.     if (access.login(username, password, accounts, ARRAY_SIZE)) {
  376.         string input;
  377.         int input2;
  378.         double input3;
  379.  
  380.         while (true) {
  381.  
  382.             if (0 <= -1 || 0 > 2) {
  383.                 // Prevents memory hacking... probably.
  384.                 // Well only if they dont know the permission system is 0 - 2.
  385.                 // If they do oh well...
  386.  
  387.                 cout << "Access Denied" << endl;
  388.                 getchar();
  389.                 getchar();
  390.                 return 0;
  391.             }
  392.  
  393.             cout << "Please Enter Command: ";
  394.             getline(cin, input);
  395.  
  396.             if (input == "Q" || input == "q") {
  397.                 // Quit (Permissions >CUSTOMER)
  398.                 return 0;
  399.             }
  400.             else if (input == "B" || input == "b") {
  401.                 // Balance (Permissions >CUSTOMER)
  402.             }
  403.             else if (input == "D" || input == "d") {
  404.                 // Deposit (Permissions >CUSTOMER)
  405.             }
  406.             else if (input == "W" || input == "w") {
  407.                 // Withdrawl (Permissions >CUSTOMER)
  408.             }
  409.             else if (input == "T" || input == "T") {
  410.                 // Transfer (Permissions <CUSTOMER)
  411.             }
  412.             else if (input == "CC" || input == "Cc") {
  413.                 // Customer Cash (Permissions <CUSTOMER)
  414.             }
  415.             else if (input == "AC" || input == "Ac" || input == "ac") {
  416.                 // Add Customer (Permissions >EMPLOYEE)
  417.             }
  418.             else if (input == "DC" || input == "Dc" || input == "dc") {
  419.                 // Delete Customer (Permissions >EMPLOYEE)
  420.             }
  421.             else if (input == "SEARCH" || input == "Search" || input == "search") {
  422.                 // Search (By name) (Permissions >EMPLOYEE)
  423.             }
  424.             else if (input == "TE" || input == "Te" || input == "te") {
  425.                 // Total Deposits (Permissions ROOT)
  426.             }
  427.             else if (input == "TD" || input == "Td" || input == "td") {
  428.                 // Total Withdrawls (Permissions ROOT)
  429.             }
  430.             else if (input == "CM" || input == "Cm" || input == "cm") {
  431.                 // Create Money (Permissions ROOT)
  432.             }
  433.             else if (input == "REHASH" || input == "Rehash" || input == "rehash") {
  434.                 // Reload Database (Permissions ROOT)
  435.             }
  436.             else if (input == "SAVE" || input == "Save" || input == "save") {
  437.                 // Save Database (Permissions ROOT)
  438.  
  439.             } else if (input == "help" || input == "HELP" || input == "Help") {
  440.            
  441.                 if (0 >= Permissions::Customer) {
  442.                     cout << endl <<
  443.                         "Current Commands for permission level: " << access.permissionname(id, accounts, ARRAY_SIZE) << endl
  444.                         << "Balance          <B>" << endl
  445.                         << "Depost           <D>" << endl
  446.                         << "Withdraw         <W>" << endl
  447.                         << "Transfer         <W>" << endl
  448.                         << "Customercash     <CC>" << endl
  449.                         << "Quit             <Q>" << endl;
  450.                 }
  451.  
  452.                 if (0 >= Permissions::Employee) {
  453.                     cout << "Addcustomer      <AC>" << endl
  454.                         << "Delcustomer      <DC>" << endl
  455.                         << "Search (by name) <search>" << endl;
  456.                 }
  457.  
  458.                 if (0 == Permissions::Root) {
  459.                     cout << "Total Employees  <TE>" << endl
  460.                          << "Total Deposits   <TD>" << endl
  461.                          << "Total Withdraws  <TW>" << endl
  462.                          << "Create Money     <CM>" << endl
  463.                          << "Reload Database  <REHASH>" << endl
  464.                          << "Save   Database  <SAVE>" << endl;
  465.                 }
  466.  
  467.                 cout << endl;
  468.             } else {
  469.                 cout << "Invalid Command, type help for list of commands, or command -help for detailed help for a command." << endl << endl;
  470.             }
  471.  
  472.         }
  473.     } else {
  474.  
  475.         // Prevents brute force attacks, memory hacking etc... probably.. in theory.
  476.         cout << endl << "You have entered an invalid login credential, for your safety this application will now terminate!";
  477.         getchar();
  478.         getchar();
  479.         return 0;
  480.     }
  481. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement