#include <iostream>
#include <string>
using namespace std;
class bankAccount
{
string password;
string firstName;
string lastName;
float accountBalance;
public:
~bankAccount();
bankAccount(string firstName, string lastName, string password, float balance);
void setPassword(string password);
void setFirstName(string firstName);
void setLastName(string lastName);
void setAccountBalance(float accountBalance);
float getAccountBalance() { return this->accountBalance; }
string getAccountName() { return this->lastName + " " + this->lastName; }
string getPassword() { return this->password; }
bool authenticate(string password);
bool deposit(float n);
bool withdrawal(float n);
bool changePassword();
};
int main()
{
bool exit = false;
bankAccount *myAccount = new bankAccount("Anthony", "Wlodarski", "plasticpen5", 2000.00);
int command = 0;
float deposit, withdrawal = 0.0;
while(!exit)
{
command = 0;
withdrawal = 0;
deposit = 0;
cout << "Please enter one of the following choices." << endl;
cout << "1. View account balance." << endl;
cout << "2. Make a deposit." << endl;
cout << "3. Make a withdrawal." << endl;
cout << "4. Change account password." << endl;
cout << "5. Exit." << endl << endl;
cin >> command;
switch(command)
{
case 1:
cout << "Your account balance is: " << myAccount->getAccountBalance() << endl;
break;
case 2:
cout << "Please enter the amount you would like to deposit (xxxx.xx format please):" << endl;
cin >> deposit;
myAccount->deposit(deposit);
break;
case 3:
cout << "Enter the amount you would like to withdraw:" << endl;
cin >> withdrawal;
myAccount->withdrawal(withdrawal);
cout << "Your account balance is: " << myAccount->getAccountBalance() << endl;
break;
case 4:
myAccount->changePassword();
break;
case 5:
exit = true;
break;
default:
cout << "You did not enter one of the above commands please try again." << endl;
}
}
delete myAccount;
return 0;
}
bankAccount::~bankAccount() {}
bankAccount::bankAccount(std::string firstName, std::string lastName, std::string password, float balance)
{
this->firstName = firstName;
this->lastName = lastName;
this->password = password;
this->accountBalance = balance;
}
void bankAccount::setPassword(string password)
{
this->password = password;
}
void bankAccount::setFirstName(string firstName)
{
this->firstName = firstName;
}
void bankAccount::setLastName(string lastName)
{
this->lastName = lastName;
}
void bankAccount::setAccountBalance(float accountBalance)
{
this->accountBalance = accountBalance;
}
bool bankAccount::authenticate(string password)
{
if(this->password == password)
{
return true;
}
else
{
return false;
}
}
bool bankAccount::deposit(float n)
{
string password = "";
cout << "Please enter your password: ";
cin >> password;
if(this->authenticate(password))
{
this->setAccountBalance(this->accountBalance + n);
cout << "Your funds have been deposited succesfully." << endl;
cout << "Your new account balance is: " << this->getAccountBalance() << endl;
return true;
}
else
{
cout << "We could not authenticate you to the system, returning to main menu." << endl;
return false;
}
}
bool bankAccount::withdrawal(float n)
{
string password = "";
cout << "Please enter your password: ";
cin >> password;
if(this->authenticate(password))
{
if(n > this->accountBalance)
{
cout << "Insufficient funds, cannot withdraw " << n << " from bank account." << endl;
return false;
}
else
{
this->setAccountBalance(this->accountBalance - n);
cout << "Please remember to take your cash and your recepit! " << endl;
return true;
}
}
else
{
cout << "We could not authenticate you to the system, returning to main menu." << endl;
return false;
}
}
bool bankAccount::changePassword()
{
string old, first, second;
cout << "Please enter your old password: ";
cin >> old;
if(this->authenticate(old))
{
cout << "Please enter your new password: ";
cin >> first;
cout << "Please enter your new password again: ";
cin >> second;
if(first == second)
{
this->setPassword(first);
cout << "Your authentication token has been updated, returning to main menu." << endl;
return true;
}
else
{
cout << "Authentication tokens did not match, returning you to the main menu." << endl;
return false;
}
}
else
{
cout << "You failed to authenticate to the system, returning to main menu." << endl;
return false;
}
}