Advertisement
Guest User

Untitled

a guest
Oct 18th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. class AutoTellerMachine { //Object to represent each customer who uses the ATM program
  2. public:
  3. void CreateNewAccount(string newUsername, string newPassword);
  4. void AccountLogin(string loginUsername, string loginPassword);
  5. void DepositMoney(double depositAmount);
  6. void WithdrawMoney(double withdrawalAmount);
  7. void SetAccountLogin(int setAccountLocation);
  8. void SetLastMoneyMovement(int accountID, double amount);
  9. void SetBeginningBalance(int accountID);
  10. void SetLastOperation(int accountID, char userInput);
  11. void AccountMenu();
  12. int GetAccountLogin() const;
  13. double GetLastMoneyMovement(int accountID) const;
  14. double GetAccountBalance(int accountID) const;
  15. double GetBeginningBalance(int accountID) const;
  16. char GetLastOperation(int accountID) const;
  17. string GetUsername(int accountID) const;
  18.  
  19. private:
  20. int loggedInAccountLocation;
  21. double accountBalance;
  22. double beginningBalance;
  23. double lastMoneyMovement;
  24. char lastOperation;
  25. string username;
  26. string password;
  27. };
  28.  
  29. AutoTellerMachine account;
  30.  
  31. vector<AutoTellerMachine> AccountList; //This vector allows for multiple accounts to be stored so that if more than one person uses the account, all information is retained
  32.  
  33. void AccountMenu();
  34. void UserMenu();
  35.  
  36. void AutoTellerMachine:: SetAccountLogin(int setAccountLocation) {
  37.  
  38. loggedInAccountLocation = setAccountLocation;
  39.  
  40. return;
  41. }
  42.  
  43. int AutoTellerMachine::GetAccountLogin() const {
  44.  
  45. return loggedInAccountLocation;
  46. }
  47.  
  48. void AutoTellerMachine::CreateNewAccount(string newUsername, string newPassword) { //Adds the new information to the vector to give the account personalized info
  49.  
  50. int accountListSize = AccountList.size();
  51.  
  52. AccountList.at(accountListSize - 1).accountBalance = 0.0;
  53. AccountList.at(accountListSize - 1).username = newUsername;
  54. AccountList.at(accountListSize - 1).password = newPassword;
  55.  
  56. }
  57.  
  58. void AutoTellerMachine::AccountLogin(string loginUsername, string loginPassword) {
  59.  
  60. int accountListSize = AccountList.size();
  61. bool successfulLogin = false;
  62. int accountLocation = 0;
  63.  
  64. for(int i = 0; i < accountListSize; i++) {
  65.  
  66. if(loginUsername == AccountList.at(i).username) {
  67.  
  68. if(loginPassword == AccountList.at(i).password) {
  69.  
  70. successfulLogin = true;
  71. accountLocation = i;
  72. }
  73. }
  74. }
  75.  
  76. if(successfulLogin != true) {
  77.  
  78. cout << endl << "******** LOGIN FAILED! ********" << endl << endl;
  79. UserMenu();
  80. }
  81.  
  82. else if(successfulLogin == true) {
  83.  
  84. SetAccountLogin(accountLocation);
  85. cout << endl << "Access Granted - " << AccountList.at(loggedInAccountLocation).username << endl;
  86. AccountMenu();
  87. }
  88.  
  89. return;
  90. }
  91.  
  92. void AutoTellerMachine::DepositMoney(double depositAmount) {
  93.  
  94. AccountList.at(loggedInAccountLocation).accountBalance += depositAmount;
  95.  
  96. return;
  97. }
  98.  
  99. void AutoTellerMachine::WithdrawMoney(double withdrawalAmount) {
  100.  
  101. AccountList.at(loggedInAccountLocation).accountBalance -= withdrawalAmount;
  102.  
  103. return;
  104. }
  105.  
  106. double AutoTellerMachine::GetAccountBalance(int accountID) const {
  107.  
  108. return AccountList.at(loggedInAccountLocation).accountBalance;
  109. }
  110.  
  111. void AutoTellerMachine::SetLastMoneyMovement(int accountID, double amount) {
  112.  
  113. AccountList.at(accountID).lastMoneyMovement = amount;
  114. }
  115.  
  116. void AutoTellerMachine::SetBeginningBalance(int accountID) {
  117.  
  118. AccountList.at(accountID).beginningBalance = AccountList.at(loggedInAccountLocation).accountBalance;
  119. }
  120.  
  121. void AutoTellerMachine::SetLastOperation(int accountID, char userInput) {
  122.  
  123. AccountList.at(accountID).lastOperation = userInput;
  124. }
  125.  
  126. double AutoTellerMachine::GetLastMoneyMovement(int accountID) const {
  127.  
  128. return AccountList.at(accountID).lastMoneyMovement;
  129. }
  130.  
  131. double AutoTellerMachine::GetBeginningBalance(int accountID) const {
  132.  
  133. return AccountList.at(accountID).beginningBalance;
  134. }
  135.  
  136. char AutoTellerMachine::GetLastOperation(int accountID) const {
  137.  
  138. return AccountList.at(accountID).lastOperation;
  139. }
  140.  
  141. string AutoTellerMachine::GetUsername(int accountID) const {
  142.  
  143. return AccountList.at(GetAccountLogin()).username;
  144. }
  145.  
  146. void UserMenu() { //Implements a user interface that allows the user to make selections based on what they want to do
  147.  
  148. char userSelection;
  149. string createUserId;
  150. string createUserPass;
  151. string usernameCheck;
  152. string passwordCheck;
  153.  
  154. cout << "l -> Login" << endl;
  155. cout << "c -> Create New Account" << endl;
  156. cout << "q -> Quit" << endl << endl << ">";
  157. cin >> userSelection;
  158.  
  159. if((userSelection == 'l') || (userSelection == 'L')) { //Checks to make sure the login is valid and if not, couts an error statement
  160.  
  161. cout << endl << "Please enter your user name: " << endl;
  162. cin >> usernameCheck;
  163. cout << "Please enter your password: " << endl;
  164. cin >> passwordCheck;
  165.  
  166. account.AccountLogin(usernameCheck, passwordCheck);
  167.  
  168. }
  169.  
  170. else if((userSelection == 'c') || (userSelection == 'C')) { //Captures info for a new account
  171.  
  172. cout << endl << "Please enter your user name: " << endl;
  173. cin >> createUserId;
  174. cout << "Please enter your password: " << endl;
  175. cin >> createUserPass;
  176.  
  177. AccountList.push_back(account); //This creates a new object in the vector to be filled with the information gathered
  178.  
  179. account.CreateNewAccount(createUserId, createUserPass);
  180.  
  181. cout << endl << "Thank You! Your account has been created!" << endl << endl;
  182.  
  183. UserMenu();
  184. }
  185.  
  186. else if((userSelection == 'q') || (userSelection == 'Q')) { //Exits the entire program
  187.  
  188. cout << endl << "You selected quit!" << endl << endl;
  189. }
  190.  
  191. else {
  192.  
  193. cout << endl << "Invalid selection." << endl;
  194. UserMenu();
  195. }
  196.  
  197. return;
  198. }
  199.  
  200. void AutoTellerMachine::AccountMenu() { //This is a separate menu from the user menu because it deals with all options available to a logged in customer
  201.  
  202. char userInput;
  203. double amountOfDeposit;
  204. double amountOfWithdrawal;
  205.  
  206. cout << endl << "d -> Deposit Money" << endl; //This has a couple more options than indicated in our project overview, but I feel they make this a more useable program
  207. cout << "w -> Withdraw Money" << endl;
  208. cout << "r -> Request Balance" << endl;
  209. cout << "z -> Logout" << endl;
  210. cout << "q -> Quit" << endl;
  211. cout << endl << ">";
  212. cin >> userInput;
  213.  
  214. if((userInput == 'd') || (userInput == 'D')) { //Deposit function that changes the balance of the account user and sets the last money movement for later use
  215.  
  216. SetBeginningBalance(GetAccountLogin());
  217. cout << endl << "Amount of deposit: " << endl;
  218. cin >> amountOfDeposit;
  219. SetLastMoneyMovement(GetAccountLogin(), amountOfDeposit);
  220. SetLastOperation(GetAccountLogin(), userInput);
  221. DepositMoney(amountOfDeposit);
  222. AccountMenu();
  223. }
  224.  
  225. else if((userInput == 'w') || (userInput == 'W')) { //Withdraw function makes sure that enough funds are present for the operation before removing money
  226.  
  227. cout << endl << "Amount of withdrawal: " << endl;
  228. cin >> amountOfWithdrawal;
  229.  
  230. if(amountOfWithdrawal > GetAccountBalance(GetAccountLogin())) {
  231.  
  232. cout << endl << "******Insfficient Funds!*******" << endl;
  233. }
  234.  
  235. else {
  236.  
  237. SetBeginningBalance(GetAccountLogin());
  238. SetLastMoneyMovement(GetAccountLogin(), amountOfWithdrawal);
  239. SetLastOperation(GetAccountLogin(), userInput);
  240. WithdrawMoney(amountOfWithdrawal);
  241. }
  242.  
  243. AccountMenu();
  244. }
  245.  
  246. else if((userInput == 'r') || (userInput == 'R')) { //Simply prints the balance before the last transaction, what type and amount the last transaction was then the current balance
  247.  
  248. cout << endl << "Beginning balance: $" << fixed << setprecision(2) << GetBeginningBalance(GetAccountLogin()) << endl;
  249.  
  250. if(GetLastOperation(GetAccountLogin()) == 'd') {
  251.  
  252. cout << "Deposit amount: $" << fixed << setprecision(2) << GetLastMoneyMovement(GetAccountLogin()) << endl;
  253. }
  254.  
  255. else if(GetLastOperation(GetAccountLogin()) == 'w') {
  256.  
  257. cout << "Withdrawal amount: $" << fixed << setprecision(2) << GetLastMoneyMovement(GetAccountLogin()) << endl;
  258. }
  259.  
  260. cout << "Your balance is $" << fixed << setprecision(2) << GetAccountBalance(GetAccountLogin()) << endl;
  261.  
  262. AccountMenu();
  263. }
  264.  
  265. else if((userInput == 'z') || (userInput == 'Z')) { //Allows the user to logout of their account and brings them back to the user menu so they can log in with a different account
  266.  
  267. cout << endl << "You have successfully logged out, " << GetUsername(GetAccountLogin()) << "!" << endl << endl;
  268. UserMenu();
  269. }
  270.  
  271. else if((userInput == 'q') || (userInput == 'Q')) { //Exits the entire program
  272.  
  273. cout << endl << "Thanks for banking with COP2513.F16, " << GetUsername(GetAccountLogin()) << "!" << endl;
  274. }
  275.  
  276. else {
  277.  
  278. cout << endl << "Invalid selection." << endl;
  279. AccountMenu();
  280. }
  281.  
  282. return;
  283. }
  284.  
  285. int main() {
  286.  
  287. cout << "Welcome to COP2513.F16’s ATM Machine" << endl << endl;
  288. cout << "Please select an option from the menu below: " << endl << endl;
  289.  
  290. UserMenu();
  291.  
  292. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement