Advertisement
LittleMax

Untitled

Jun 3rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #define SIZE 4
  5. using namespace std;
  6.  
  7. struct Plane {
  8.     char company[30];
  9.     char surname[30];
  10.     char name[30];
  11.     int flight;
  12.     int price;
  13.  
  14.     Plane() {}
  15.     Plane(char company[30], char surname[30], char name[30], int flight, int price)
  16.     {
  17.         memcpy(this->name, name, sizeof(name));
  18.         memcpy(this->surname, surname, sizeof(surname));
  19.         memcpy(this->company, company, sizeof(company));
  20.         this->flight = flight;
  21.         this->price = price;
  22.     }
  23. };
  24.  
  25. void add(Plane* planes)
  26. {
  27.     for (int i = 0; i < SIZE; i++)
  28.     {
  29.         char name[30];
  30.         char surname[30];
  31.         char company[30];
  32.         int flight;
  33.         int price;
  34.  
  35.         cout << "Enter company, name, surname, flight and price of ticket" << endl;
  36.         cin >> name >> surname >> company >> flight >> price;
  37.  
  38.         memcpy(planes[i].name, name, sizeof(name));
  39.         memcpy(planes[i].surname, surname, sizeof(surname));
  40.         memcpy(planes[i].company, company, sizeof(company));
  41.         planes[i].flight = flight;
  42.         planes[i].price = price;
  43.     }
  44. }
  45.  
  46. void show(Plane* pl)
  47. {
  48.     for (int i = 0; i < SIZE; i++)
  49.     {
  50.         cout << "Company: " << pl[i].company << endl;
  51.         cout << "Name: " << pl[i].name << " Surname: " << pl[i].surname << endl;
  52.         cout << "Flight: " << pl[i].flight << endl;
  53.         cout << "Price: " << pl[i].price << endl;
  54.     }
  55. }
  56.  
  57. void findFlight(Plane* p, const char comp[30])
  58. {
  59.     for (int i = 0; i < SIZE; i++)
  60.     {
  61.         if (p[i].company == comp)
  62.         {
  63.             cout << "Flight: " << p->flight << endl;
  64.         }
  65.     }
  66. }
  67.  
  68. void findPassengers(Plane* p, int flight)
  69. {
  70.     vector<char[30]> passengers;
  71.     for (int i = 0; i < SIZE; i++)
  72.     {
  73.         if (p[i].flight == flight)
  74.         {
  75.             passengers.push_back(p[i].surname);
  76.         }
  77.     }
  78.  
  79.     sort(passengers.begin(), passengers.end());
  80.  
  81.     for (auto x : passengers)
  82.         cout << x << endl;
  83. }
  84.  
  85. int main()
  86. {
  87.     Plane* planes = new Plane[SIZE];
  88.     add(planes);
  89.     findFlight(planes, "jmix");
  90.  
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement