The actual files lol

This commit is contained in:
2023-06-29 14:33:39 -07:00
parent c63d71664f
commit fe1bd55f73
3 changed files with 231 additions and 0 deletions

50
account.cpp Normal file
View File

@@ -0,0 +1,50 @@
//account class file
#include <iostream>
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;
};

2
data.txt Normal file
View File

@@ -0,0 +1,2 @@
1234 3557.02
2345 500.66

179
main.cpp Normal file
View File

@@ -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 <iostream>
#include <fstream>
#include <map>
#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<int, account> 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;
}