Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <vector>
- using namespace std;
- class AutoTellerMachine {
- public:
- void CreateNewAccount(string newUsername, string newPassword);
- void AccountLogin(string loginUsername, string loginPASSWORD);
- void DepositMoney(double depositAmount);
- void WithdrawMoney(double withdrawalAmount);
- void SetAccountLogin(int setAccountLocation);
- void SetLastMoneyMovement(int accountID, double amount);
- void SetBeginningBalance(int accountID);
- void SetLastOperation(int accountID, char userInput);
- void AccountMenu();
- int GetAccountLogin() const;
- double GetLastMoneyMovement(int accountID) const;
- double GetAccountBalance(int accountID) const;
- double GetBeginningBalance(int accountID) const;
- char GetLastOperation(int accountID) const;
- string GetUsername(int accountID) const;
- private:
- int loggedInAccountLocation;
- double accountBalance;
- double beginningBalance;
- double lastMoneyMovement;
- char lastOperation;
- string username;
- string password;
- };
- AutoTellerMachine account;
- vector<AutoTellerMachine> AccountList;
- void AccountMenu();
- void UserMenu();
- void AutoTellerMachine:: SetAccountLogin(int setAccountLocation) {
- loggedInAccountLocation = setAccountLocation;
- return;
- }
- int AutoTellerMachine:: GetAccountLogin() const {
- return loggedInAccountLocation;
- }
- void AutoTellerMachine::CreateNewAccount(string newUsername, string newPassword) {
- int accountListSize = AccountList.size();
- AccountList.at(accountListSize - 1).accountBalance = 0.0;
- AccountList.at(accountListSize - 1).username = newUsername;
- AccountList.at(accountListSize - 1).password = newPassword;
- }
- void AutoTellerMachine::AccountLogin(string loginUsername, string loginPassword) {
- int accountListSize = AccountList.size();
- bool successfulLogin = false;
- int accountLocation = 0;
- for(int i = 0; i < accountListSize; i++) {
- if(loginUsername == AccountList.at(i).username) {
- if(loginPassword == AccountList.at(i).password) {
- successfulLogin = true;
- accountLocation = i;
- }
- }
- }
- if(successfulLogin != true) {
- cout << endl << "******** LOGIN FAILED! ********" << endl << endl;
- UserMenu();
- }
- else if(successfulLogin == true) {
- SetAccountLogin(accountLocation);
- cout << endl << "Access Granted - " <<
- AccountList.at(loggedInAccountLocation).username << endl;
- AccountMenu();
- }
- return;
- }
- void AutoTellerMachine::DepositMoney(double depositAmount) {
- AccountList.at(loggedInAccountLocation).accountBalance += depositAmount;
- return;
- }
- void AutoTellerMachine::WithdrawMoney(double withdrawalAmount) {
- AccountList.at(loggedInAccountLocation).accountBalance -= withdrawalAmount;
- return;
- }
- double AutoTellerMachine::GetAccountBalance(int accountID) const {
- return AccountList.at(loggedInAccountLocation).accountBalance;
- }
- void AutoTellerMachine::SetLastMoneyMovement(int accountID, double amount) {
- AccountList.at(accountID).lastMoneyMovement = amount;
- }
- void AutoTellerMachine::SetBeginningBalance(int accountID) {
- AccountList.at(accountID).beginningBalance =
- AccountList.at(loggedInAccountLocation).accountBalance;
- }
- void AutoTellerMachine::SetLastOperation(int accountID, char userInput) {
- AccountList.at(accountID).lastOperation = userInput;
- }
- double AutoTellerMachine::GetLastMoneyMovement(int accountID) const {
- return AccountList.at(accountID).lastMoneyMovement;
- }
- double AutoTellerMachine::GetBeginningBalance(int accountID) const {
- return AccountList.at(accountID).beginningBalance;
- }
- char AutoTellerMachine::GetLastOperation(int accountID) const {
- return AccountList.at(accountID).lastOperation;
- }
- string AutoTellerMachine::GetUsername(int accountID) const {
- return AccountList.at(GetAccountLogin()).username;
- }
- void UserMenu() {
- char userSelection;
- string createUserId;
- string createUserPass;
- string usernameCheck;
- string passwordCheck;
- cout << "l -> Login" << endl;
- cout << "c -> Create New Account" << endl;
- cout << "q -> Quit" << endl << endl << ">";
- cin >> userSelection;
- if((userSelection == 'l') || (userSelection == 'L')) {
- cout << endl << "Please enter your user name: " << endl;
- cin >> usernameCheck;
- cout << "Please enter your password: " << endl;
- cin >> passwordCheck;
- account.AccountLogin(usernameCheck, passwordCheck);
- }
- else if ((userSelection == 'c') || (userSelection == 'C')) {
- cout << endl << "Please enter your user name: " << endl;
- cin >> createUserId;
- cout << "Please enter your password: " << endl;
- cin >> createUserPass;
- AccountList.push_back(account);
- account.CreateNewAccount(createUserId, createUserPass);
- cout << endl << "Thank you! Your account has been created!" << endl << endl;
- UserMenu();
- }
- else if((userSelection == 'q') || (userSelection == 'Q')) {
- cout << endl << "You selected quit!" << endl << endl;
- }
- else {
- cout << endl << "Invalid Selection." << endl;
- UserMenu();
- }
- return;
- }
- void AutoTellerMachine::AccountMenu() {
- char userInput;
- double amountofDeposit;
- double amountofWithdrawal;
- cout << endl << "d -> Deposit Money" << endl;
- cout << "w -> Withdraw Money" << endl;
- cout << "r -> Request Balance" << endl;
- cout << "z -> Logout" << endl;
- cout << "q -> Quit" << endl;
- cout << endl << ">";
- cin >> userInput;
- if((userInput == 'd') || (userInput == 'D')) {
- SetBeginningBalance(GetAccountLogin());
- cout << endl << "Amount of deposit: " << endl;
- cin >> amountofDeposit;
- SetLastMoneyMovement(GetAccountLogin(), amountofDeposit);
- SetLastOperation(GetAccountLogin(), userInput);
- DepositMoney(amountofDeposit);
- AccountMenu();
- }
- else if ((userInput == 'w') || (userInput == 'W')) {
- cout << endl << "Amount of withdrawal: " << endl;
- cin >> amountofWithdrawal;
- if(amountofWithdrawal > GetAccountBalance(GetAccountLogin())) {
- cout << endl << "******Insufficient Funds!******" << endl;
- }
- else {
- SetBeginningBalance(GetAccountLogin());
- SetLastMoneyMovement(GetAccountLogin(), amountofWithdrawal);
- SetLastOperation(GetAccountLogin(), userInput);
- WithdrawMoney(amountofWithdrawal);
- }
- AccountMenu();
- }
- else if ((userInput == 'r') || (userInput == 'R')) {
- cout << endl << "Beginning balance: $" << fixed << setprecision(2) << GetBeginningBalance(GetAccountLogin()) << endl;
- if(GetLastOperation(GetAccountLogin()) == 'd') {
- cout << "Deposit amount: $" << fixed << setprecision(2) << GetLastMoneyMovement(GetAccountLogin()) << endl;
- }
- else if(GetLastOperation(GetAccountLogin()) == 'w') {
- cout << "Withdrawal Amount: $" << fixed << setprecision(2) << GetAccountBalance(GetAccountLogin()) << endl;
- }
- cout << "Your balance is $" << fixed << setprecision(2) << GetAccountBalance(GetAccountLogin()) << endl;
- AccountMenu();
- }
- else if ((userInput == 'z') || (userInput == 'Z')) {
- cout << endl << "You have successfully logged out, " << GetUsername(GetAccountLogin()) << "!" << endl << endl;
- UserMenu();
- }
- else if ((userInput == 'q') || (userInput == 'Q')) {
- cout << endl << "Thanks for banking with Wells Fargo, " << GetUsername(GetAccountLogin()) << "!" << endl;
- }
- else {
- cout << endl << "Invalid Selection." << endl;
- AccountMenu();
- }
- return;
- }
- int main() {
- cout << "Welcome to Well Fargo's ATM Machine." << endl << endl;
- cout << "Please select an option from the menu below: " << endl << endl;
- UserMenu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement