Advertisement
Razorspined

Untitled

Jan 18th, 2023
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. enum SIZE  {
  8.     S,
  9.     M,
  10.     L,
  11. };
  12.  
  13. class Vehicle {
  14. public:
  15.     // "S", "M", "L"
  16.     SIZE size;
  17.     int number;
  18.  
  19.     Vehicle() {
  20.    
  21.     }
  22.  
  23.     Vehicle(SIZE s, int n) {
  24.         size = s;
  25.         number = n;
  26.  
  27.         // &&
  28.         // ||
  29.         if ((number/100000) < 1 || (number / 100000) >= 10) {
  30.             //cout << "registracionniq nomer ne e 6 cifri" << endl;
  31.         }
  32.     }
  33. };
  34.  
  35. class ParkingSpace {
  36. private:
  37.     SIZE size;
  38.     int number;
  39.     bool taken; // true (1) ; false (0)
  40.  
  41. public:
  42.     friend class Parking;
  43.     ParkingSpace() {
  44.         taken = false;
  45.         number = 0;
  46.     }
  47.  
  48.     ParkingSpace(SIZE s) {
  49.         size = s;
  50.         taken = false;
  51.         number = 0;
  52.     }
  53.  
  54.     // name, return type, parameters, body
  55.     void operator+(Vehicle v) {
  56.         if (size > v.size) {
  57.             taken = true;
  58.             number = v.number;
  59.         }
  60.     }
  61. };
  62.  
  63. class Parking {
  64. public:
  65.     vector<ParkingSpace> spaces;
  66.  
  67.     void totalSpaces() {
  68.         int small = 0;
  69.         int medium = 0;
  70.         int large = 0;
  71.         for (ParkingSpace space : spaces) {
  72.             if (space.size == SIZE::S) small++;
  73.             else if (space.size == SIZE::M) medium++;
  74.             else if (space.size == SIZE::L) large++;
  75.         }
  76.         cout << small << "," << medium << "," << large << endl;
  77.     }
  78.  
  79.         void freeSpacesBySize(SIZE s) {
  80.             int counter = 0;
  81.  
  82.             // ||
  83.             // &&
  84.             for (ParkingSpace space : spaces) {
  85.                 if (space.size == s && space.taken == false) counter++;
  86.             }
  87.  
  88.             cout << counter << endl;
  89.         }
  90. };
  91.  
  92. int main() {
  93.     Vehicle v1;
  94.     v1.size = SIZE::M;
  95.     v1.number = 123456;
  96.     Vehicle v2(SIZE::L, 123456);
  97.  
  98.     vector<int> n = { 2,4,6,8 };
  99.  
  100.     for (int x : n) {
  101.         cout << x;
  102.     }
  103.  
  104.     for (int i = 0; i < n.size(); i++) {
  105.         cout << n[i];
  106.     }
  107.  
  108.     Parking p;
  109.     p.freeSpacesBySize(SIZE::M);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement