Advertisement
xotohop

parking_reoper

Apr 25th, 2020
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class parking
  6. {
  7.     private:
  8.         string name = "Unecon_Parking";
  9.         string location = "Griboedova_32";
  10.         int space = 50;
  11.         int rate = 25;
  12.         int free_; // для удобного подсчета свободных мест
  13.     public:
  14.         parking()
  15.         {
  16.             string name;
  17.             string location;
  18.             int space;
  19.             int rate;
  20.         };
  21.         parking operator - (int arrived)
  22.         {
  23.             if (free_ - arrived >= 0)
  24.             {
  25.                 free_ -= arrived;
  26.                 return *this;
  27.             }
  28.             else
  29.                 cout << "no parking spaces" << endl;
  30.         }
  31.         parking operator + (int left)
  32.         {
  33.             if (free_ + left <= space)
  34.             {
  35.                 free_ += left;
  36.                 return *this;
  37.             }
  38.             else
  39.                 cout << "can't leave more cars than it was" << endl;
  40.         }
  41.         void set();
  42.         void free();
  43.         ~parking(){}
  44. };
  45.  
  46. int main()
  47. {  
  48.     int left;
  49.     int arrived;
  50.     int temp;
  51.     int option = -1;
  52.     parking parking_;
  53.     parking free_;
  54.     parking_.set();
  55.     while (option != 3)
  56.     {
  57.         cout << "enter the option:" << endl;
  58.         cout << "1. car arrived" << endl;
  59.         cout << "2. car left" << endl;
  60.         cout << "3. exit" << endl;
  61.         cin >> option;
  62.         switch (option)
  63.         {
  64.             case 1:
  65.                 cout << "cars arrived: "; cin >> arrived;
  66.                 parking_ - arrived;
  67.                 break;
  68.             case 2:
  69.                 cout << "cars left: "; cin >> left;
  70.                 parking_ + left;
  71.                 break;
  72.             case 3:
  73.                 break;
  74.         }
  75.         parking_.free();
  76.     }
  77.     return 0;
  78. }
  79.  
  80. void parking::free()
  81. {
  82.     cout << "free spaces: " << free_ << endl;
  83.     return;
  84. }
  85.  
  86. void parking::set()
  87. {
  88.     cout << "create new parking ..." << endl;
  89.     cout << "name: " << name << endl;
  90.     cout << "location: " << location << endl;
  91.     cout << "space: " << space << endl;
  92.     cout << "rate: " << rate << endl;
  93.     free_ = space;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement