Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class root {
- private:
- const std::string currentDateTime() {
- time_t now = time(0);
- struct tm tstruct;
- char buf[80];
- tstruct = *localtime(&now);
- strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
- return buf;
- }
- Account* accounts;
- protected:
- int ARRAY_SIZE;
- public:
- root(int SIZE);
- void initializeAccounts() {
- accounts = new Account[ARRAY_SIZE];
- }
- void unloadAccounts() {
- delete this;
- }
- // ====== 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)
- void listEmployees() {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].Permissions == Permissions::Employee) {
- if (accounts[i].account != -1) {
- cout
- << "=======================================" << endl
- << "Account Infomation: " << endl
- << "Account #: " << accounts[i].account << endl
- << "Username: " << accounts[i].username << endl;
- }
- }
- }
- }
- // Not added to the options/command list!!!! <================================== <- Fixed
- void listAdmin() {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].Permissions == Permissions::Root) {
- if (accounts[i].account != -1) {
- cout
- << "=======================================" << endl
- << "Account Infomation: " << endl
- << "Account #: " << accounts[i].account << endl
- << "Username: " << accounts[i].username << endl;
- }
- }
- }
- }
- // Sorry about the CTRL + C CTRL + V code, I normally dont do this, just for time sake. Need to debug other things then worry about
- // Fixing this code so its more robust.
- void totalDeposits() { // <--- Needs work
- string date;
- string td = currentDateTime();
- std::string delimiter = ".";
- size_t pos = 0;
- std::string token;
- while ((pos = td.find(delimiter)) != std::string::npos) {
- token = td.substr(0, pos);
- date = token;
- break;
- td.erase(0, pos + delimiter.length());
- }
- string filename;
- ifstream data;
- data.open("log_file.txt");
- // Exit on I/O error
- if (!data.is_open()) {
- cout << "Failed to open file, press enter to exit";
- getchar();
- getchar();
- }
- double amount = 0;
- while (!data.eof()) {
- string date2 = "";
- string timestamp = "";
- string type;
- double in = 0;
- string dummy = "";
- data >> timestamp >> type >> dummy >> in;
- td = timestamp;
- data.ignore();
- while ((pos = td.find(delimiter)) != std::string::npos) {
- token = td.substr(0, pos);
- date2 = token;
- td.erase(0, pos + delimiter.length());
- }
- if (type == "Deposit") {
- if (date == date2) {
- amount += in;
- }
- }
- }
- cout << "Todays Total Deposits: " << amount << endl;
- }
- void totalWithdrawl() { // <--- Needs Work
- string date;
- string td = currentDateTime();
- std::string delimiter = ".";
- size_t pos = 0;
- std::string token;
- while ((pos = td.find(delimiter)) != std::string::npos) {
- token = td.substr(0, pos);
- date = token;
- break;
- td.erase(0, pos + delimiter.length());
- }
- string filename;
- ifstream data;
- data.open("log_file.txt");
- // Exit on I/O error
- if (!data.is_open()) {
- cout << "Failed to open file, press enter to exit";
- getchar();
- getchar();
- }
- double amount = 0;
- while (!data.eof()) {
- string date2 = "";
- string timestamp = "";
- string type;
- double in = 0;
- string dummy = "";
- while ((pos = td.find(delimiter)) != std::string::npos) {
- token = td.substr(0, pos);
- date2 = token;
- td.erase(0, pos + delimiter.length());
- }
- data >> timestamp >> type >> dummy >> in;
- data.ignore();
- td = timestamp;
- while ((pos = td.find(delimiter)) != std::string::npos) {
- token = td.substr(0, pos);
- date2 = token;
- td.erase(0, pos + delimiter.length());
- }
- if (type == "Withdraw") {
- if (date == date2) {
- amount += in;
- }
- }
- }
- cout << "Todays Total Withdrawl: " << amount << endl;
- }
- void viewLog() {
- ifstream myReadFile;
- myReadFile.open("log_file.txt");
- char output[100];
- if (myReadFile.is_open()) {
- while (!myReadFile.eof()) {
- myReadFile >> output;
- cout << output;
- }
- }
- cout << endl;
- myReadFile.close();
- }
- void reloadDatabase() {
- // Clean DB
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- // Clean up and remove user!
- accounts[i].account = -1;
- accounts[i].username = "";
- accounts[i].password = "";
- accounts[i].cash = 0;
- accounts[i].money = 0;
- accounts[i].type = AccountType::Checking;
- accounts[i].Permissions = Permissions::Customer;
- }
- string filename;
- ifstream data;
- int account;
- string username;
- string password;
- string firstname;
- string lastname;
- double cash;
- double money;
- int type;
- int permissions;
- data.open("members.db");
- // Exit on I/O error
- if (!data.is_open()) {
- cout << "Failed to open file...";
- getchar();
- getchar();
- }
- int i = 0;
- while (!data.eof()){
- data >> account >> username >> password >> firstname >> lastname >> cash >> money >> type >> permissions;
- accounts[i].account = account;
- accounts[i].username = username;
- accounts[i].password = password;
- accounts[i].firstName = firstname;
- accounts[i].lastName = lastname;
- accounts[i].cash = cash;
- accounts[i].money = money;
- accounts[i].type = static_cast<AccountType>(type);
- accounts[i].Permissions = static_cast<Permissions>(permissions);
- i++;
- }
- }
- void saveDatabase() {
- if (remove("members.db") != 0){
- cout << "Error deleting file";
- }
- ofstream membersdb("members.db");
- if (membersdb.is_open())
- {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].account != -1) {
- if (i != 0) {
- membersdb << endl; // Duct tape over a real issue.
- }
- membersdb << accounts[i].account << " " << accounts[i].username << " " << accounts[i].password
- << " " << accounts[i].firstName << " " << accounts[i].lastName
- << " " << accounts[i].cash << " " << accounts[i].money << " " << accounts[i].type
- << " " << accounts[i].Permissions;
- }
- }
- }
- membersdb.close();
- }
- bool createMoney(double ammount, int customerid) {
- if (customerid != -1) {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].account == customerid) {
- accounts[i].money = accounts[i].money + ammount;
- break;
- }
- }
- }
- else {
- return false;
- }
- }
- bool addCustomer(string username, string password, string firstname, string lastname, Permissions permissions, AccountType accounttype) { //AC
- bool found = false;
- int AccountID = -1;
- /*
- // Account # Algorithm (will break after 2000, unless the array size is changed)
- for (int i = 0; i <= size - 1; i++) {
- for (int b = 0; b <= size - 1; b++) {
- if (accounts[i].account == b) {
- found = true;
- }
- if (found == true) {
- AccountID = b;
- break;
- }
- }
- }
- */
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].account == -1) {
- accounts[i].account = i + 1;
- accounts[i].username = username;
- accounts[i].password = password;
- accounts[i].firstName = firstname;
- accounts[i].lastName = lastname;
- accounts[i].type = accounttype;
- accounts[i].Permissions = permissions;
- cout << "Success! Account #: " << i + 1;
- return true;
- break;
- }
- }
- return false;
- }
- bool delCustomer(int customerid) { // DC
- if (customerid != -1) {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].account == customerid) {
- // Clean up and remove user!
- accounts[i].account = -1;
- accounts[i].username = "";
- accounts[i].password = "";
- accounts[i].cash = 0;
- accounts[i].money = 0;
- accounts[i].type = AccountType::Checking;
- accounts[i].Permissions = Permissions::Customer;
- return true;
- break;
- }
- }
- }
- return false;
- }
- // Case Sensitive!
- void search(string customername) { // search
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].firstName == customername) {
- cout << "Account Infomation: " << endl
- << "Account #: " << accounts[i].account << endl
- << "Username: " << accounts[i].username << endl
- << "Money (in checking): " << accounts[i].money << endl
- << "Account Type: " << accounts[i].type << endl
- << "Permissions: " << accounts[i].Permissions << endl;
- }
- }
- }
- void balance(int customerid) { // <B>
- if (customerid != -1) {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (customerid == accounts[i].account) {
- cout << "Current balance: " << accounts[i].money << endl;
- }
- }
- }
- }
- bool depost(int customerid, double amount) { // <D>
- if (customerid != -1) {
- for (int i = 0; i <= ARRAY_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) { // <W>
- if (customerid != -1) {
- for (int i = 0; i <= ARRAY_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;
- }
- bool transfer(int customerid, double amount, int accountid) { // <W>
- if (customerid != -1) {
- int myaccount = -1;
- // Find my account number (index).
- for (int i = 0; i <= ARRAY_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 <= ARRAY_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) { // <CC>
- if (customerid != -1) {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if (accounts[i].account == customerid) {
- cout << "Your current cash is: " << accounts[i].cash << endl;
- break;
- }
- }
- }
- }
- bool login(string username, string password) {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- // Case Sensitive ALL FEILDS!
- if ((username == accounts[i].username) && (password == accounts[i].password)) {
- return true;
- }
- }
- return false;
- }
- int getAccount(string username) {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if ((username == accounts[i].username)) {
- return accounts[i].account;
- }
- }
- return -1;
- }
- int permission(int customerid) {
- for (int i = 0; i <= ARRAY_SIZE - 1; i++) {
- if ((customerid == accounts[i].account)) {
- return accounts[i].Permissions;
- }
- }
- return -1;
- }
- string permissionname(int permissionlvl) {
- 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";
- }
- }
- ~root(void);
- };
- root::root(int SIZE) // constuctor
- {
- ARRAY_SIZE = SIZE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement