Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Project: Basic Banking Software Database
- // Name: Brandan Tyler Lasley
- // Date: 1/30/2014 18:57
- // should this be an economy where money can't be created or destroyed? Maybe a default cash? like a real bank?
- // This will be based on a level system from 0 - 2
- // 0 Customer
- // 1 Employee
- // 2 Boss (root?)
- // ====== CUSTOMER ======
- // Balance
- // Depost
- // Withdraw
- // Transfer
- // Total Cash (optional, A place to withdrawl money, employee or bank shouldn't beable to NSA spy on the customer?)
- // ====== EMPLOYEE ======
- // Everything above
- // Add customer (account)
- // Delete customer (account)
- // Search records using "Name" using Swquential search
- // ====== BOSS ======
- // Everything in the bank teller and customer
- // List total number of employees in bank
- // List Ttoal amount of money in the bank
- // Total deposits in a day
- // total withdrawls in a day
- // Abillity to see detailed log of all transactions
- // Sort databade (optional)
- // Create money (optional)
- // Remember to declare constants or a varible to control ALL ARRAYS!
- // Completed (0/16) levels (0/3)
- // Todo:
- // Customer
- // Employee
- // Boss
- // Know Issues & Limiatations:
- // Max 2000 customers
- // If you use the illegal char '◦' anywhere in the program it will corrupt the database, I may fix this.
- // I have no idea how a credit card, savings, or 'instant access' works. So those wasn't added.
- // Before I started this project, I wrote an entire program in VB.NET using structs of arrays and classes
- // that scrapes live 911 call data off WCCCA's Civic data. To see if I knew it well enough to write this program.
- // 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
- // to manage and my webhost isn't yelling at me about memory useage.
- // 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
- // that would've made my life eaiser.
- // Thanks for forcing me to learn structs, also enums were quite intesting.
- #include <iostream>
- #include <string>
- #include <fstream>
- #include<stdio.h>
- #include<conio.h>
- #include "BBSD.h"
- using namespace std;
- char db_char = '◦';
- enum AccountType {
- unknown = -1, Checking, Savings, CreditCard, InstantAccess
- };
- enum Permissions {
- Customer, Employee, Root
- };
- struct Account {
- // Login Info
- string username;
- string password;
- int account;
- string firstName;
- string lastName;
- AccountType type;
- Permissions Permissions;
- float money; // Money is like debit
- float cash; // Cash is what the 'customer' has on hand. hypothetical.
- };
- struct Log {
- int account;
- string timestamp;
- string method;
- int successful;
- float amount;
- };
- class customer {
- // ====== CUSTOMER ======
- // Balance
- // Depost
- // Withdraw (and transfer)
- // Total Cash (optional, A place to withdrawl money, employee or bank shouldn't beable to NSA spy on the customer?)
- public:
- void balance(int customerid, Account accounts[], int size) { // <B>
- for (int i = 0; i = size - 1; i++) {
- if (customerid == accounts[i].account) {
- cout << "Your current balance: " << accounts[i].money << endl;
- }
- }
- cout << "Could not find account!" << endl;
- }
- bool depost(int customerid, double amount, Account accounts[], int size) { // <D>
- for (int i = 0; i = size - 1; i++) {
- if (customerid == accounts[i].account) {
- if (amount > accounts[i].cash) {
- cout << "You do not have enough cash to make this deposit!" << endl;
- return false;
- }
- else {
- accounts[i].money = accounts[i].money + amount;
- accounts[i].cash = accounts[i].cash - amount;
- cout << "Deposit Successful! Amount: " << amount << endl;
- return true;
- }
- }
- }
- cout << "Could not find account!" << endl;
- return false;
- }
- bool withdraw(int customerid, double amount, Account accounts[], int size) { // <W>
- for (int i = 0; i = size - 1; i++) {
- if (customerid == accounts[i].account) {
- if (amount > accounts[i].money) {
- cout << "You do not have enough money to make this withdrawl!" << endl;
- return false;
- } else {
- accounts[i].money = accounts[i].money - amount;
- accounts[i].cash = accounts[i].cash + amount;
- cout << "Withdraw Successful! Amount: " << amount << endl;
- return true;
- }
- }
- }
- cout << "Could not find account!" << endl;
- return false;
- }
- // I dont know enough about banks to impliment it the way you want it... is a Checkings/Savings account on a completely
- // different account or is it the same account just with a struct and can a credit card go into the negitives!??
- // ATMs dont allow you to transfer funds anyways, atleast not any that I've used.
- // This function will simpily transfer it from one account to the other, this is a debit type system because i've only used a
- // debit card and have no idea how anything else works. No negatives, no debt.
- // I do enjoy how you leave most of the project up to your imagination and research though.
- bool transfer(int customerid, double amount, int accountid, Account accounts[], int size) { // <W>
- int myaccount = -1;
- // Find my account number (index).
- for (int i = 0; i = size - 1; i++) {
- if (customerid == accounts[i].account) {
- myaccount = i;
- }
- }
- if (myaccount == -1) {
- return false;
- }
- // Find the account number of the transfer person.
- for (int i = 0; i = size - 1; i++) {
- if (accountid == accounts[i].account) {
- if (accounts[myaccount].money < amount) { // < means less than, abit dyslexic when it comes to <> so I get it wrong, its the other way.
- return false;
- } else {
- accounts[myaccount].money = accounts[myaccount].money - amount;
- accounts[i].money = accounts[i].money + amount;
- cout << "Transfer Successful! Amount: " << amount << endl;
- return true;
- }
- }
- }
- cout << "Could not find account!" << endl;
- return true;
- }
- void customercash(int customerid, Account accounts[], int size) { // <CC>
- for (int i = 0; i = size - 1; i++) {
- if (accounts[i].account == customerid) {
- cout << "Your current cash is: " << accounts[i].cash << endl;
- break;
- }
- }
- }
- };
- class empolyee {
- // ====== EMPLOYEE ======
- // Everything above
- // Add customer (account)
- // Delete customer (account)
- // Search records using "Name" using Swquential search
- public:
- bool addCustomer(int customerid, Account accounts[], int size) { //AC
- for (int i = 0; i = size - 1; i++) {
- if (accounts[i].account == NULL) {
- // Add new account! (username, password, other stuff; needs more function values!)
- return true;
- break;
- }
- }
- return false;
- }
- bool delCustomer(int customerid, Account accounts[], int size) { // DC
- for (int i = 0; i = size - 1; i++) {
- if (accounts[i].account == customerid) {
- // Add new account! (username, password, other stuff; needs more function values!)
- return true;
- break;
- }
- }
- return false;
- }
- std::string search(std::string customername, Account accounts[], int size) { // search
- for (int i = 0; i = size - 1; i++) {
- if (accounts[i].firstName == customername) {
- // Print out customer infomation!
- }
- }
- }
- };
- class root {
- // ====== BOSS ======
- // Everything in the bank teller and customer
- // List total number of employees in bank
- // List total amount of money in the bank
- // Total deposits in a day
- // total withdrawls in a day
- // Abillity to see detailed log of all transactions
- // Sort databade (optional)
- // Create money (optional)
- // Reload DB (optional)
- // Save DB (optional)
- public:
- string listEmployees(Account accounts[], int size) {
- return "None";
- }
- void totalDeposits() { // <--- Needs work
- }
- void totalWithdrawl() { // <--- Needs Work
- }
- void viewLog() { // <<----- Needs work
- }
- bool reloadDatabase(Account accounts[], int size) {
- return true;
- }
- bool saveDatabase(Account accounts[], int size) {
- return true;
- }
- bool createMoney(double ammount, int customerid, Account accounts[], int size) {
- string input;
- cout << "Are you sure you want to 'Create Money', This could very well crash our economy" << endl << "Answer (Y/N): ";
- cin >> input;
- if ((input == "Y" || input == "y")) {
- }
- else {
- return false;
- }
- }
- };
- class security {
- // This will be based on a level system from 0 - 2
- // 0 Customer
- // 1 Employee
- // 2 Boss (root?)
- public:
- bool login(string username, string password, Account accounts[], int size) {
- for (int i = 0; i = size - 1; i++) {
- if ((username == accounts[i].username) && (username == accounts[i].password)) {
- return true;
- }
- }
- return false;
- }
- int getAccount(string username, Account accounts[], int size) {
- for (int i = 0; i = size - 1; i++) {
- if ((username == accounts[i].username)) {
- return accounts[i].account;
- }
- }
- }
- string permissionname(int permissionlvl, Account accounts[], int size) {
- if (permissionlvl == Permissions::Customer) {
- return "Customer";
- }
- else if (permissionlvl == Permissions::Employee) {
- return "Employee";
- }
- else if (permissionlvl == Permissions::Root) {
- return "Root/Administrator";
- } else {
- return "Malicious User";
- }
- }
- };
- // How do we do the account # thing for the current user logged in?
- // Do we just load the info at start?
- // Should we also ask if they want to deposit to another user?
- // Transer?
- int main() {
- // Class Declarisons
- security access;
- customer customer;
- empolyee empolyee;
- root root;
- // Array size 2000, MAX Customers.
- const int ARRAY_SIZE = 2000;
- // Username & Password, this is a secure system.
- string username;
- string password;
- // Declare Struct
- Account accounts[ARRAY_SIZE];
- customer.withdraw(0, 0, accounts, ARRAY_SIZE);
- int id = access.getAccount(username, accounts, ARRAY_SIZE); // Gets the ID, faster to seek than searching strings, good pratice for MySQL also.
- cout << "Welcome to Brandans Banking System!" << endl;
- cout << "Username: ";
- cin >> username; // Usernames cannot contains spaces
- getchar(); // Fix annoying auto input from enter.
- cout << "Password: ";
- getline(cin, password);// It would be stupid to restirct passwords though.
- // ==== Login ====
- if (access.login(username, password, accounts, ARRAY_SIZE)) {
- string input;
- int input2;
- double input3;
- while (true) {
- if (0 <= -1 || 0 > 2) {
- // Prevents memory hacking... probably.
- // Well only if they dont know the permission system is 0 - 2.
- // If they do oh well...
- cout << "Access Denied" << endl;
- getchar();
- getchar();
- return 0;
- }
- cout << "Please Enter Command: ";
- getline(cin, input);
- if (input == "Q" || input == "q") {
- // Quit (Permissions >CUSTOMER)
- return 0;
- }
- else if (input == "B" || input == "b") {
- // Balance (Permissions >CUSTOMER)
- }
- else if (input == "D" || input == "d") {
- // Deposit (Permissions >CUSTOMER)
- }
- else if (input == "W" || input == "w") {
- // Withdrawl (Permissions >CUSTOMER)
- }
- else if (input == "T" || input == "T") {
- // Transfer (Permissions <CUSTOMER)
- }
- else if (input == "CC" || input == "Cc") {
- // Customer Cash (Permissions <CUSTOMER)
- }
- else if (input == "AC" || input == "Ac" || input == "ac") {
- // Add Customer (Permissions >EMPLOYEE)
- }
- else if (input == "DC" || input == "Dc" || input == "dc") {
- // Delete Customer (Permissions >EMPLOYEE)
- }
- else if (input == "SEARCH" || input == "Search" || input == "search") {
- // Search (By name) (Permissions >EMPLOYEE)
- }
- else if (input == "TE" || input == "Te" || input == "te") {
- // Total Deposits (Permissions ROOT)
- }
- else if (input == "TD" || input == "Td" || input == "td") {
- // Total Withdrawls (Permissions ROOT)
- }
- else if (input == "CM" || input == "Cm" || input == "cm") {
- // Create Money (Permissions ROOT)
- }
- else if (input == "REHASH" || input == "Rehash" || input == "rehash") {
- // Reload Database (Permissions ROOT)
- }
- else if (input == "SAVE" || input == "Save" || input == "save") {
- // Save Database (Permissions ROOT)
- } else if (input == "help" || input == "HELP" || input == "Help") {
- if (0 >= Permissions::Customer) {
- cout << endl <<
- "Current Commands for permission level: " << access.permissionname(id, accounts, ARRAY_SIZE) << endl
- << "Balance <B>" << endl
- << "Depost <D>" << endl
- << "Withdraw <W>" << endl
- << "Transfer <W>" << endl
- << "Customercash <CC>" << endl
- << "Quit <Q>" << endl;
- }
- if (0 >= Permissions::Employee) {
- cout << "Addcustomer <AC>" << endl
- << "Delcustomer <DC>" << endl
- << "Search (by name) <search>" << endl;
- }
- if (0 == Permissions::Root) {
- cout << "Total Employees <TE>" << endl
- << "Total Deposits <TD>" << endl
- << "Total Withdraws <TW>" << endl
- << "Create Money <CM>" << endl
- << "Reload Database <REHASH>" << endl
- << "Save Database <SAVE>" << endl;
- }
- cout << endl;
- } else {
- cout << "Invalid Command, type help for list of commands, or command -help for detailed help for a command." << endl << endl;
- }
- }
- } else {
- // Prevents brute force attacks, memory hacking etc... probably.. in theory.
- cout << endl << "You have entered an invalid login credential, for your safety this application will now terminate!";
- getchar();
- getchar();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement