Advertisement
xotohop

parking_final

May 6th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 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_ = space; // для удобного подсчета свободных мест
  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.         friend void set(const parking & parking_);
  42.         friend void free_spaces(const parking & parking_);
  43.         ~parking(){}
  44. };
  45.  
  46. void set(const parking & parking_)
  47. {
  48.     cout << "create new parking ..." << endl;
  49.     cout << "name: " << parking_.name << endl;
  50.     cout << "location: " << parking_.location << endl;
  51.     cout << "space: " << parking_.space << endl;
  52.     cout << "rate: " << parking_.rate << endl;
  53. }
  54.  
  55. void free_spaces(const parking & parking_)
  56. {
  57.     cout << "free spaces: " << parking_.free_ << endl;
  58. }
  59.  
  60. int main()
  61. {  
  62.     int left;
  63.     int arrived;
  64.     int temp;
  65.     int option = -1;
  66.     parking parking_;
  67.     parking free_;
  68.     set(parking_);
  69.     while (option != 3)
  70.     {
  71.         cout << "enter the option:" << endl;
  72.         cout << "1. car arrived" << endl;
  73.         cout << "2. car left" << endl;
  74.         cout << "3. exit" << endl;
  75.         cin >> option;
  76.         switch (option)
  77.         {
  78.             case 1:
  79.                 cout << "cars arrived: "; cin >> arrived;
  80.                 parking_ - arrived;
  81.                 break;
  82.             case 2:
  83.                 cout << "cars left: "; cin >> left;
  84.                 parking_ + left;
  85.                 break;
  86.             case 3:
  87.                 break;
  88.         }
  89.         free_spaces(parking_);
  90.     }
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement