Advertisement
Foxyzboi

перегрузка с вводом

Dec 26th, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Bankomat
  5. {
  6. public:
  7. Bankomat() :Id(0), currentMoney(0) {}
  8. void setId(int i);
  9. int getId();
  10. int getMoneyCount();
  11. void depositMoney(int i);
  12. void withdrawMoney(int i);
  13. private:
  14. int Id;
  15. int currentMoney;
  16. enum { max = 1000, min = 10 };
  17. };
  18.  
  19. void Bankomat::withdrawMoney(int i)
  20. {
  21. if ((i < min) || (i > max)) {
  22. return;
  23. }
  24. if ((currentMoney - i) < 0) {
  25. }
  26. currentMoney -= i;
  27. }
  28.  
  29. void Bankomat::depositMoney(int i) {
  30. if ((i < min) || (i > max)) {
  31. return;
  32. }
  33. if ((currentMoney + i) > max) {
  34. return;
  35. }
  36. currentMoney = i;
  37. }
  38.  
  39. void Bankomat::setId(int i)
  40. {
  41. Id = i;
  42. }
  43.  
  44. int Bankomat::getId()
  45. {
  46. return Id;
  47. }
  48.  
  49. int Bankomat::getMoneyCount()
  50. {
  51. return currentMoney;
  52. }
  53.  
  54. ostream& operator << (ostream& os, Bankomat& bank)
  55. {
  56. return os << bank.getMoneyCount();
  57. }
  58.  
  59.  
  60. int main()
  61. {
  62. Bankomat bank;
  63. bank.setId(123);
  64. int i = 0;
  65. cin >> i;
  66. bank.depositMoney(i);
  67. cout << bank << endl;
  68. bank.withdrawMoney(100);
  69. cout << bank << endl;
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement