Advertisement
Guest User

Untitled

a guest
Nov 27th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. Institution ID : Your name
  2. Course: “CIS2513”
  3. Term: “Fall 2016”
  4. Vector list of Bank Accounts [created during the online session]
  5.  
  6. A Savings Account
  7. A Line of Credit Account
  8. A Checking Account
  9.  
  10. Current Balance (which may be positive or negative)
  11. A vector list of transactions
  12. Transaction Type
  13. Credit
  14. Debit
  15.  
  16. #include <iostream>
  17. #include <fstream>
  18. #include <string>
  19. #include <cstring>
  20. #include <stdlib.h>
  21. using namespace std;
  22.  
  23. class BankAccount {
  24. public:
  25. BankAccount();
  26. BankAccount(string usrName, string usrPassword);
  27.  
  28. void CreateAccount(string userName, string userPassword);
  29. bool LoginInfo(string userName, string userPassword);
  30. void DepositMoney();
  31. void WithdrawMoney();
  32. void RequestBalance();
  33.  
  34. static double savingBalance = 0.00;
  35. static double checkingBalance = 500.00;
  36. static double accountBalance = 0.0;
  37. double creditLine = 0.00;
  38. double newBalance = 0.00;
  39. double depositAmount, withdrawalAmount;
  40.  
  41. private:
  42. string usrName;
  43. string usrPassword;
  44. };
  45.  
  46. BankAccount::BankAccount() {
  47. usrName = "";
  48. usrPassword = "";
  49. return;
  50. }
  51.  
  52. BankAccount::BankAccount(string user_Name, string user_Password) {
  53. usrName = user_Name;
  54. usrPassword = user_Password;
  55. return;
  56. }
  57.  
  58. void BankAccount::CreateAccount(string userName, string userPassword){
  59. ofstream outFS;
  60. outFS.open("bankAccounts.txt");
  61. outFS << userName << endl;
  62. outFS << userPassword << endl;
  63. outFS.close();
  64. return;
  65. }
  66.  
  67. bool BankAccount::LoginInfo(string userName, string userPassword){
  68. ifstream inFS;
  69. inFS.open("bankAccounts.txt");
  70.  
  71. string name;
  72. string password;
  73.  
  74. if (inFS.is_open())
  75. {
  76. while (inFS >> name)
  77. {
  78. inFS >> password;
  79. if (userName == name && userPassword == password){
  80. return true;
  81. }
  82. }
  83. }
  84. inFS.close();
  85.  
  86. return false;
  87. }
  88.  
  89. void BankAccount::BankAccount::DepositMoney(){
  90. char usrOption;
  91. char depositVal[50];
  92. int length;
  93.  
  94. cout << "Amount of deposit: ";
  95. cin >> depositVal;
  96.  
  97. length = strlen(depositVal);
  98. if(depositVal[0] == '$')
  99. {
  100. for(int i = 0; i < length; i++) {
  101. depositVal[i] = depositVal[i + 1];
  102. }
  103. }
  104. depositAmount = atof(depositVal);
  105.  
  106. newBalance = accountBalance + depositAmount;
  107. accountBalance = newBalance;
  108. return;
  109. }
  110.  
  111. void BankAccount::BankAccount::WithdrawMoney(){
  112. char usrOption;
  113. char withdrawalVal[50];
  114. int length;
  115.  
  116. cout << "Amount of withdrawal: ";
  117. cin >> withdrawalVal;
  118.  
  119. length = strlen(withdrawalVal);
  120. if(withdrawalVal[0] == '$')
  121. {
  122. for(int i = 0; i < length; i++) {
  123. withdrawalVal[i] = withdrawalVal[i + 1];
  124. }
  125. }
  126. withdrawalAmount = atof(withdrawalVal);
  127.  
  128. newBalance = accountBalance - withdrawalAmount;
  129. accountBalance = newBalance;
  130. return;
  131. }
  132.  
  133. void BankAccount::BankAccount::RequestBalance() {
  134. if (newBalance < 0)
  135. {
  136. creditLine = newBalance;
  137. savingBalance = 0.0;
  138. checkingBalance = 0.0;
  139. }
  140. else
  141. {
  142. creditLine = 0.0;
  143. }
  144. savingBalance = newBalance - checkingBalance;
  145.  
  146. cout << "Your SAVINGS balance is: $" << savingBalance << endl;
  147. cout << "Your CHECKING balance is: $" << checkingBalance << endl;
  148. cout << "Your LINE OF CREDIT balance is: $" << creditLine << endl;
  149. cout << "Your TOTAL Balance is: $" << newBalance << endl;
  150. return;
  151. }
  152.  
  153. int main() {
  154. string usrName;
  155. string usrPassword;
  156. char usrOption;
  157.  
  158. cout << "Welcome to our ATM Machine" << endl;
  159. cout << endl;
  160.  
  161. while (true){
  162. cout << "Please select an option:" << endl;
  163. cout << endl;
  164.  
  165. cout << "l -> Login" << endl;
  166. cout << "c -> Create New Account" << endl;
  167. cout << "q -> Quit" << endl;
  168. cout << endl;
  169.  
  170. cin >> usrOption;
  171. cout << endl;
  172.  
  173. switch (usrOption){
  174. case 'l':
  175. case 'L':
  176. cout << "Please enter your user id: ";
  177. cin >> usrName;
  178. cout << "Please enter your password: ";
  179. cin >> usrPassword;
  180.  
  181. if (LoginInfo(usrName, usrPassword)){
  182. cout << endl;
  183. cout << "Access Granted - " << usrName << endl;
  184. cout << endl;
  185.  
  186. while (true)
  187. {
  188. cout << "d -> Deposit Money" << endl;
  189. cout << "w -> Withdraw Money" << endl;
  190. cout << "r -> Request Balance" << endl;
  191. cout << "x -> Exit" << endl;
  192. cout << endl;
  193.  
  194. cin >> usrOption;
  195. cout << endl;
  196.  
  197. switch (usrOption){
  198. case 'd':
  199. case 'D':
  200. DepositMoney();
  201. break;
  202.  
  203. case 'w':
  204. case 'W':
  205. WithdrawMoney();
  206. break;
  207.  
  208. case 'r':
  209. case 'R':
  210. RequestBalance();
  211. break;
  212.  
  213. case 'x':
  214. case 'X':
  215. cout << "Thanks for banking with us, " << usrName << "!" << endl;
  216. exit(1);
  217. break;
  218.  
  219. default:
  220. cout << "Invalid option. Pick again." << endl;
  221. break;
  222. }
  223. cout << endl;
  224. }
  225. }
  226. else {
  227. cout << endl;
  228. cout << "******** LOGIN FAILED! ********" << endl;
  229. }
  230. break;
  231.  
  232. case 'c':
  233. case 'C':
  234. cout << "Please enter your user name: ";
  235. cin >> usrName;
  236. cout << "Please enter your password: ";
  237. cin >> usrPassword;
  238. CreateAccount(usrName, usrPassword);
  239.  
  240. cout << endl;
  241. cout << "Thank You! Your account has been created!" << endl;
  242. break;
  243.  
  244. case 'q':
  245. case 'Q':
  246. exit(1);
  247. break;
  248.  
  249. default:
  250. cout << "Invalid option. Pick again." << endl;
  251. }
  252. cout << endl;
  253. }
  254.  
  255. return 0;
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement