Advertisement
Foxyzboi

исправленная перегрузка

Dec 26th, 2022
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 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.         cout << "Sorry but max = 1000, min = 10";
  23.         return;
  24.     }
  25.     if ((currentMoney - i) < 0) {
  26.         cout << "Problem" << endl
  27.             << "get max: " << currentMoney << endl;
  28.     }
  29.     currentMoney -= i;
  30. }
  31.  
  32. void Bankomat::depositMoney(int i) {
  33.     if ((i < min) || (i > max)) {
  34.         cout << "Sorry but max = 1000, min = 10";
  35.         return;
  36.     }
  37.     if ((currentMoney + i) > max) {
  38.         cout << "Please insert max = " << max - currentMoney << endl;
  39.         return;
  40.     }
  41.     currentMoney = i;
  42. }
  43.  
  44. void Bankomat::setId(int i)
  45. {
  46.     Id = i;
  47. }
  48.  
  49. int Bankomat::getId()
  50. {
  51.     return Id;
  52. }
  53.  
  54. int Bankomat::getMoneyCount()
  55. {
  56.     return currentMoney;
  57. }
  58.  
  59. ostream& operator << (ostream& os, Bankomat& bank)
  60. {
  61.     return os << bank.getMoneyCount();
  62. }
  63.  
  64. int main()
  65. {
  66.     Bankomat bank;
  67.     bank.setId(123);
  68.     bank.depositMoney(500);
  69.     cout << bank << endl;
  70.     bank.withdrawMoney(100);
  71.     cout << bank << endl;
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement