diff --git a/account.cpp b/account.cpp new file mode 100644 index 0000000..250adfc --- /dev/null +++ b/account.cpp @@ -0,0 +1,50 @@ +//account class file +#include +using namespace std; + +class account +{ +public: + + account(short set_pin) + { + pin = set_pin; + } + +void deposit(double deposit) +{ + balance += deposit; + cout << "Succesfully deposited $" << deposit << endl; + cout << "New balance is: $" << balance << endl << endl; +} + + +void withdraw(double withdrawl) +{ +if (balance - withdrawl < 0) { +cout << "Error: Not enough money in balance"; +} + +else +{ + balance -= withdrawl; + cout << "Succesfully withdrew $" << withdrawl << endl; + cout << "New balance is: $" << balance << endl << endl; +} +} + +void set_bal(double new_bal) { balance = new_bal; } +bool test_pin(short int pin_attmpt) { +if (pin_attmpt == pin) + return true; +else + return false; +} +void set_pin(short int new_pin) { pin = new_pin; } +void printBal() { cout << "$" << balance << endl << endl; } +double txt_file_bal() { return balance; } +private: +double balance; +short acnt_num; +short int pin; +}; diff --git a/data.txt b/data.txt new file mode 100644 index 0000000..fbe0ab0 --- /dev/null +++ b/data.txt @@ -0,0 +1,2 @@ +1234 3557.02 +2345 500.66 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..903f30e --- /dev/null +++ b/main.cpp @@ -0,0 +1,179 @@ +//CURRENT BUILD BETA 3.85 +//Author Alex Kiraly + +/************************ +TODO: +-Have write to file in binary +-admin mode for list, adding, removing accounts etc. + +REDO +entire things. Bank class, should be a class for each account to store things. + +the whole damn thing has to be resturctured, only salvable part is logo and account class. Account class already had right idea, just need to add to it. + +Main will run the main loop + +class bank: +stores all accts -- Map with an id for each? -- +admin services for creating/deleting/veiwing accounts on the cli +will be responsible for reading and writing the BINARY file + +class account: +stores: check balanace, save balance, pin, holder name +functions for transfers and what not. + +***********************/ +#include +#include +#include +#include "account.cpp" +using namespace std; + + +void print_logo() +{ + cout << " ### ## ##\n"; + cout << " ## ## ## ##\n"; + cout << " ## ## ## ##\n"; + cout << " ########## ####\n"; + cout << " ## ## ## ##\n"; + cout << "## ## ## ##\n"; +} + +int main() +{ + //Variable initialization + int usr_ac, pin_atmpt, t_acc; + char usr_inp = NULL; + //create acounts + account james(1234); + account paul(9876); + //Initaite maps of account numbers to their class member + map acc_list; + acc_list.insert(make_pair(1234, james)); + acc_list.insert(make_pair(2345, paul)); + + + //Read data.txt for values of each account + ifstream infile("data.txt"); + int a; + double b; + while (infile >> a >> b) + { + acc_list[a].set_bal(b); + + } + infile.close(); + + //Print welcome logo and message + print_logo(); + cout << "Welcome to AK banking. What is your account number?\n:"; + + //Get user acount name + cin >> usr_ac; + + //User gets 5 tries to enter their accounts passcode + //If not broken(correct pin) then terminates program with failure + for (int tries = 5; tries >= 0; tries--) + { + cout << "Enter pin: "; + cin >> pin_atmpt; + + if (acc_list[usr_ac].test_pin(pin_atmpt)) + break; + + else { + cout << "Incorrect pin " << tries << " attempts left\n"; + } + //EXIT_FAILURE + if (tries == 0) + exit(1); + + } + + //TODO /////////////////////////////////////////////////////////////////////////////////// PRINT NAME TO IT + cout << "Welcome\n"; + + //Main part. While the user has chosen not to quit + while (toupper(usr_inp) != 'Q') + { + double amount; + //Get what user wants to do + cout << "Press D to deposit, W to withdraw, B for balance, T to transfer to another account, q to quit\n:"; + cin >> usr_inp; + + switch (toupper(usr_inp)) + { + //if user chooses to deposit + case 'D': + for (;;) { + cout << "How much to deposit?\n:"; + //check if amount enterd is a propor float + if (!(cin >> amount) || amount < 0.0) { + cout << "Invalid input, please enter a positive value." << endl; + cin.clear(); + } + else { + break; + } + } + //If all checks pass, deposit amount + acc_list[usr_ac].deposit(amount); + break; + + //if choose to withdraw + case 'W': + for (;;) { + cout << "How much to withdraw?\n:"; + //Checks if propor float + if (!(cin >> amount) || amount < 0.0) { + cout << "Invalid input, please enter a positive value." << endl; + cin.clear(); + } + else { + break; + } + } + //if checks pass, withdraw that amount + acc_list[usr_ac].withdraw(amount); + break; + + case 'B': + acc_list[usr_ac].printBal(); + break; + + case 'T': + //If user wants to transfer funds to another account + cout << "Which acount would you like to transfer funds to?\n:"; + cin >> t_acc; + cout << "How much would you like to transfer?\n:"; + cin >> amount; + + acc_list[usr_ac].withdraw(amount); + acc_list[t_acc].deposit(amount); + cout << "Succesfully transferd $" << amount; + break; + + default: + cout << "Thats not an option, try again"; + break; + } + + + + } + + //print final balances to txt file + ofstream outfile; + outfile.open("data.txt"); + for (auto const& p : acc_list) + { + outfile << p.first << ' ' << acc_list[p.first].txt_file_bal() << '\n'; + } + + //outfile << usr_ac << " " << acc_list[usr_ac].txt_file_bal(); + outfile.close(); + + cout << "Goodbye"; + return 0; +}