Advertisement
Foxyzboi

ПЕРЕГРУЗКА С ВВОДОМ

Dec 27th, 2022
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 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.     friend istream& operator>>(istream&, Bankomat&);
  14. private:
  15.     int Id;
  16.     int currentMoney;
  17.     enum { max = 1000, min = 10 };
  18. };
  19.  
  20. void Bankomat::withdrawMoney(int i)
  21. {
  22.     if ((i < min) || (i > max)) {
  23.         return;
  24.     }
  25.     if ((currentMoney - i) < 0) {
  26.     }
  27.     currentMoney -= i;
  28. }
  29.  
  30. void Bankomat::depositMoney(int i) {
  31.     if ((i < min) || (i > max)) {
  32.         return;
  33.     }
  34.     if ((currentMoney + i) > max) {
  35.         return;
  36.     }
  37.     currentMoney = i;
  38. }
  39.  
  40. void Bankomat::setId(int i)
  41. {
  42.     Id = i;
  43. }
  44.  
  45. int Bankomat::getId()
  46. {
  47.     return Id;
  48. }
  49.  
  50. int Bankomat::getMoneyCount()
  51. {
  52.     return currentMoney;
  53. }
  54.  
  55. ostream& operator << (ostream& os, Bankomat& bank)
  56. {
  57.     return os << bank.getMoneyCount();
  58. }
  59.  
  60. istream& operator>>(istream& in, Bankomat& bank)
  61. {
  62.     in >> bank.Id;
  63.     return in;
  64. }
  65.  
  66.  
  67. int main()
  68. {
  69.     Bankomat bank;
  70.     cout << "Enter id of ATM: ";
  71.     cin >> bank;
  72.     int i = 0;
  73.     cin >> i;
  74.     bank.depositMoney(i);
  75.     cout << bank << endl;
  76.     bank.withdrawMoney(100);
  77.     cout << bank << endl;
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement