Advertisement
Guest User

Untitled

a guest
Jun 14th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. class AutoTellerMachine {
  8. public:
  9. void CreateNewAccount(string newUsername, string newPassword);
  10. void AccountLogin(string loginUsername, string loginPASSWORD);
  11. void DepositMoney(double depositAmount);
  12. void WithdrawMoney(double withdrawalAmount);
  13. void SetAccountLogin(int setAccountLocation);
  14. void SetLastMoneyMovement(int accountID, double amount);
  15. void SetBeginningBalance(int accountID);
  16. void SetLastOperation(int accountID, char userInput);
  17. void AccountMenu();
  18. int GetAccountLogin() const;
  19. double GetLastMoneyMovement(int accountID) const;
  20. double GetAccountBalance(int accountID) const;
  21. double GetBeginningBalance(int accountID) const;
  22. char GetLastOperation(int accountID) const;
  23. string GetUsername(int accountID) const;
  24.  
  25. private:
  26. int loggedInAccountLocation;
  27. double accountBalance;
  28. double beginningBalance;
  29. double lastMoneyMovement;
  30. char lastOperation;
  31. string username;
  32. string password;
  33. };
  34.  
  35. AutoTellerMachine account;
  36.  
  37. vector<AutoTellerMachine> AccountList;
  38.  
  39. void AccountMenu();
  40. void UserMenu();
  41.  
  42. void AutoTellerMachine:: SetAccountLogin(int setAccountLocation) {
  43. loggedInAccountLocation = setAccountLocation;
  44.  
  45. return;
  46. }
  47.  
  48. int AutoTellerMachine:: GetAccountLogin() const {
  49. return loggedInAccountLocation;
  50. }
  51.  
  52. void AutoTellerMachine::CreateNewAccount(string newUsername, string newPassword) {
  53. int accountListSize = AccountList.size();
  54.  
  55. AccountList.at(accountListSize - 1).accountBalance = 0.0;
  56. AccountList.at(accountListSize - 1).username = newUsername;
  57. AccountList.at(accountListSize - 1).password = newPassword;
  58. }
  59.  
  60. void AutoTellerMachine::AccountLogin(string loginUsername, string loginPassword) {
  61. int accountListSize = AccountList.size();
  62. bool successfulLogin = false;
  63. int accountLocation = 0;
  64.  
  65. for(int i = 0; i < accountListSize; i++) {
  66. if(loginUsername == AccountList.at(i).username) {
  67.  
  68. if(loginPassword == AccountList.at(i).password) {
  69.  
  70. successfulLogin = true;
  71.  
  72. accountLocation = i;
  73.  
  74. }
  75. }
  76. }
  77. if(successfulLogin != true) {
  78. cout << endl << "******** LOGIN FAILED! ********" << endl << endl;
  79. UserMenu();
  80. }
  81. else if(successfulLogin == true) {
  82. SetAccountLogin(accountLocation);
  83. cout << endl << "Access Granted - " <<
  84. AccountList.at(loggedInAccountLocation).username << endl;
  85. AccountMenu();
  86. }
  87. return;
  88. }
  89.  
  90. void AutoTellerMachine::DepositMoney(double depositAmount) {
  91. AccountList.at(loggedInAccountLocation).accountBalance += depositAmount;
  92. return;
  93. }
  94.  
  95. void AutoTellerMachine::WithdrawMoney(double withdrawalAmount) {
  96. AccountList.at(loggedInAccountLocation).accountBalance -= withdrawalAmount;
  97. return;
  98. }
  99.  
  100. double AutoTellerMachine::GetAccountBalance(int accountID) const {
  101. return AccountList.at(loggedInAccountLocation).accountBalance;
  102. }
  103.  
  104. void AutoTellerMachine::SetLastMoneyMovement(int accountID, double amount) {
  105. AccountList.at(accountID).lastMoneyMovement = amount;
  106. }
  107.  
  108. void AutoTellerMachine::SetBeginningBalance(int accountID) {
  109.  
  110. AccountList.at(accountID).beginningBalance =
  111. AccountList.at(loggedInAccountLocation).accountBalance;
  112. }
  113.  
  114. void AutoTellerMachine::SetLastOperation(int accountID, char userInput) {
  115. AccountList.at(accountID).lastOperation = userInput;
  116. }
  117.  
  118. double AutoTellerMachine::GetLastMoneyMovement(int accountID) const {
  119. return AccountList.at(accountID).lastMoneyMovement;
  120. }
  121. double AutoTellerMachine::GetBeginningBalance(int accountID) const {
  122. return AccountList.at(accountID).beginningBalance;
  123. }
  124.  
  125. char AutoTellerMachine::GetLastOperation(int accountID) const {
  126. return AccountList.at(accountID).lastOperation;
  127. }
  128.  
  129. string AutoTellerMachine::GetUsername(int accountID) const {
  130. return AccountList.at(GetAccountLogin()).username;
  131. }
  132.  
  133. void UserMenu() {
  134.  
  135. char userSelection;
  136. string createUserId;
  137. string createUserPass;
  138. string usernameCheck;
  139. string passwordCheck;
  140.  
  141. cout << "l -> Login" << endl;
  142. cout << "c -> Create New Account" << endl;
  143. cout << "q -> Quit" << endl << endl << ">";
  144. cin >> userSelection;
  145.  
  146. if((userSelection == 'l') || (userSelection == 'L')) {
  147.  
  148. cout << endl << "Please enter your user name: " << endl;
  149. cin >> usernameCheck;
  150. cout << "Please enter your password: " << endl;
  151. cin >> passwordCheck;
  152.  
  153. account.AccountLogin(usernameCheck, passwordCheck);
  154. }
  155. else if ((userSelection == 'c') || (userSelection == 'C')) {
  156. cout << endl << "Please enter your user name: " << endl;
  157. cin >> createUserId;
  158. cout << "Please enter your password: " << endl;
  159. cin >> createUserPass;
  160.  
  161. AccountList.push_back(account);
  162.  
  163. account.CreateNewAccount(createUserId, createUserPass);
  164. cout << endl << "Thank you! Your account has been created!" << endl << endl;
  165. UserMenu();
  166. }
  167. else if((userSelection == 'q') || (userSelection == 'Q')) {
  168. cout << endl << "You selected quit!" << endl << endl;
  169. }
  170. else {
  171. cout << endl << "Invalid Selection." << endl;
  172. UserMenu();
  173. }
  174. return;
  175. }
  176.  
  177. void AutoTellerMachine::AccountMenu() {
  178. char userInput;
  179. double amountofDeposit;
  180. double amountofWithdrawal;
  181.  
  182. cout << endl << "d -> Deposit Money" << endl;
  183. cout << "w -> Withdraw Money" << endl;
  184. cout << "r -> Request Balance" << endl;
  185. cout << "z -> Logout" << endl;
  186. cout << "q -> Quit" << endl;
  187. cout << endl << ">";
  188. cin >> userInput;
  189.  
  190. if((userInput == 'd') || (userInput == 'D')) {
  191.  
  192. SetBeginningBalance(GetAccountLogin());
  193. cout << endl << "Amount of deposit: " << endl;
  194. cin >> amountofDeposit;
  195. SetLastMoneyMovement(GetAccountLogin(), amountofDeposit);
  196. SetLastOperation(GetAccountLogin(), userInput);
  197. DepositMoney(amountofDeposit);
  198. AccountMenu();
  199. }
  200. else if ((userInput == 'w') || (userInput == 'W')) {
  201. cout << endl << "Amount of withdrawal: " << endl;
  202. cin >> amountofWithdrawal;
  203. if(amountofWithdrawal > GetAccountBalance(GetAccountLogin())) {
  204. cout << endl << "******Insufficient Funds!******" << endl;
  205. }
  206. else {
  207. SetBeginningBalance(GetAccountLogin());
  208. SetLastMoneyMovement(GetAccountLogin(), amountofWithdrawal);
  209. SetLastOperation(GetAccountLogin(), userInput);
  210. WithdrawMoney(amountofWithdrawal);
  211. }
  212. AccountMenu();
  213. }
  214. else if ((userInput == 'r') || (userInput == 'R')) {
  215.  
  216. cout << endl << "Beginning balance: $" << fixed << setprecision(2) << GetBeginningBalance(GetAccountLogin()) << endl;
  217. if(GetLastOperation(GetAccountLogin()) == 'd') {
  218.  
  219. cout << "Deposit amount: $" << fixed << setprecision(2) << GetLastMoneyMovement(GetAccountLogin()) << endl;
  220. }
  221. else if(GetLastOperation(GetAccountLogin()) == 'w') {
  222.  
  223. cout << "Withdrawal Amount: $" << fixed << setprecision(2) << GetAccountBalance(GetAccountLogin()) << endl;
  224. }
  225. cout << "Your balance is $" << fixed << setprecision(2) << GetAccountBalance(GetAccountLogin()) << endl;
  226. AccountMenu();
  227. }
  228. else if ((userInput == 'z') || (userInput == 'Z')) {
  229. cout << endl << "You have successfully logged out, " << GetUsername(GetAccountLogin()) << "!" << endl << endl;
  230. UserMenu();
  231. }
  232. else if ((userInput == 'q') || (userInput == 'Q')) {
  233.  
  234. cout << endl << "Thanks for banking with Wells Fargo, " << GetUsername(GetAccountLogin()) << "!" << endl;
  235. }
  236. else {
  237. cout << endl << "Invalid Selection." << endl;
  238. AccountMenu();
  239. }
  240. return;
  241. }
  242. int main() {
  243. cout << "Welcome to Well Fargo's ATM Machine." << endl << endl;
  244. cout << "Please select an option from the menu below: " << endl << endl;
  245.  
  246. UserMenu();
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement