Advertisement
Guest User

Untitled

a guest
May 26th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include "ATM.h"
  2. #include "User.h"
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ATM::ATM()
  8. {
  9. currentUser = NULL;
  10. if (!LoadFromFile())
  11. {
  12. cout << "Failed to load user list";
  13. }
  14. }
  15.  
  16. void ATM::AuthUser()
  17. {
  18. string login, password;
  19. cout << "Enter login:\n>";
  20. getline(cin >> ws, login);
  21. cout << "Enter password:\n>";
  22. getline(cin >> ws, password);
  23. if (Auth(login, password))
  24. {
  25. cout << "Success!" << endl;
  26. system("pause");
  27. }
  28. else
  29. {
  30. cout << "Error!" << endl;
  31. system("pause");
  32. }
  33. }
  34.  
  35. bool ATM::Auth(string ALogin, string APassword)
  36. {
  37. if (Users.find(ALogin) != Users.end())
  38. {
  39. if (Users[ALogin].CheckPassword(APassword))
  40. {
  41. currentUser = &Users[ALogin];
  42. return true;
  43. }
  44. }
  45. return false;
  46. }
  47.  
  48. int ATM::MoneyOperation()
  49. {
  50. system("cls");
  51. int amount;
  52. cin >> amount;
  53. try
  54. {
  55. do
  56. {
  57.  
  58. if (currentUser == NULL)
  59. {
  60. cout << "Log in!" << endl;
  61. return 0;
  62. }
  63. else
  64. {
  65. cout << "Enter Amount: " << endl;
  66. cin >> amount;
  67. if (amount > 0 && amount > currentUser->balance)
  68. {
  69. cout << "You have no such means! Request a smaller amount." << endl;
  70. }
  71. else
  72. {
  73. currentUser->balance = currentUser->balance - amount;
  74. cout << "Success!";
  75. }
  76. }
  77. } while (amount > 0 && amount > currentUser->balance);
  78. return amount;
  79. }
  80. catch (string amount)
  81. {
  82. cout << "Requires Input Numbers! " << endl;
  83. }
  84. return 0;
  85. }
  86.  
  87.  
  88. bool ATM::PayMobile()
  89. {
  90. system("cls");
  91. long MobileNumber;
  92. cin >> MobileNumber;
  93. try
  94. {
  95. do
  96. {
  97.  
  98. if (currentUser == NULL)
  99. {
  100. cout << "Log in!" << endl;
  101. return 0;
  102. }
  103. else
  104. {
  105. cout << "How much you want to take? " << endl;
  106. cin >> MobileNumber;
  107. if (MobileNumber > 9000000000 && MobileNumber < 9999999999)
  108. {
  109. MoneyOperation();
  110. }
  111. else
  112. {
  113. cout << "Requires Input Numbers! " << endl;
  114. }
  115. }
  116. } while (amount > 0 && amount > currentUser->balance);
  117. return amount;
  118. }
  119. catch (string amount)
  120. {
  121. cout << "Requires Input Numbers! " << endl;
  122. }
  123. return 0;
  124. }
  125.  
  126. bool ATM::PayISP()
  127. {
  128. return true;
  129. }
  130.  
  131. string ATM::FormPaymentReceipt()
  132. {
  133. return "";
  134. }
  135.  
  136. bool ATM::LoadFromFile()
  137. {
  138. ifstream myfile("users.txt");
  139. string line;
  140. try {
  141. if (myfile) // same as: if (myfile.good())
  142. {
  143. while (!myfile.eof()) // same as: while (getline( myfile, line ).good())
  144. {
  145. string login, password;
  146. float balance;
  147.  
  148. getline(myfile, login);
  149. getline(myfile, password);
  150. getline(myfile, line);
  151. balance = stof(line);
  152.  
  153. User tmpUser(login, password, balance);
  154. Users[login] = tmpUser;
  155. }
  156. myfile.close();
  157. }
  158. }
  159. catch (const ifstream::failure& e)
  160. {
  161. return false;
  162. }
  163. return true;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement