Advertisement
selebry

zxcghoulkillmesoweakplsdontblamemehelpmewtfiamdoing

Mar 28th, 2022
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.09 KB | None | 0 0
  1. /*
  2.  
  3. Поисковик туров. Структура записи по туру: страна, дата начала, дата завершения, отель (категория по звездам), тип питания (, «все включено», шведский стол, завтрак в отелях),
  4. вид отдыха (пляжный, активный, экскурсионный), стоимость тура.
  5. Операции
  6. 1)  Заполнение записи по одному туру с клавиатуры.
  7. 2)  Вставить сведения по туру в таблицу, упорядочивая по стране. Новая запись вставляется как последняя запись в подсписок по стране.
  8. 3)  Удалить сведения по завершенным турам.
  9. 4)  Сформировать список туров в страну по предполагаемой стоимости.
  10.  
  11. */
  12.  
  13.  
  14.  
  15. #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  16. #define _CRT_SECURE_NO_WARNINGS
  17. #pragma warning(disable:4996)
  18. #endif
  19. #include <iostream>
  20. #include <string>
  21. #include <windows.h>
  22. #include <ctime>
  23. #define L long long
  24. #define N 1000
  25. using namespace std;
  26.  
  27. struct date {
  28.     unsigned short day, month;
  29.     unsigned int year;
  30. };
  31.  
  32. struct Tour {
  33.     string country;
  34.     date date_start, date_end;
  35.     unsigned short hotel_stars;
  36.     string type_eating;
  37.     string type_rest;
  38.     L price;
  39. };
  40. struct Table {
  41.     int size = 0;
  42.     const int max_size = N;
  43.     Tour tours[N];
  44. };
  45. void insert(Tour*, int&, int, Tour);
  46. void erase(Tour*, int&, int);
  47. bool compareByCountry(const Tour, const Tour);
  48. void inputTour(Tour&);
  49. void insertDataTour(Tour*, int&, Tour);
  50. date getCurDate();
  51. void deleteOutdatedTours(Tour* t, int& size);
  52. void searchToursByPrice(Tour* toursByPrice, int& sizeByPrice, Tour* tours, int size, L price);
  53. int main()
  54. {
  55.     SetConsoleCP(1251);
  56.     SetConsoleOutputCP(1251);
  57.     Table t,tByPrice;
  58.     for (int i = 0; i < 2; i++) {
  59.         Tour tmp;
  60.         inputTour(tmp);
  61.         insertDataTour(t.tours, t.size, tmp);
  62.     }
  63.     for (int i = 0; i < t.size; i++) {
  64.         cout << t.tours[i].country << '\n'
  65.             << t.tours[i].hotel_stars << '\n'
  66.             << t.tours[i].price << '\n';
  67.     }
  68.     deleteOutdatedTours(t.tours,t.size);
  69.     for (int i = 0; i < t.size; i++) {
  70.         cout << t.tours[i].country << '\n'
  71.             << t.tours[i].hotel_stars << '\n'
  72.             << t.tours[i].price << '\n';
  73.     }
  74.     searchToursByPrice(tByPrice.tours, tByPrice.size,t.tours,t.size,1500);
  75.     for (int i = 0; i < tByPrice.size; i++) {
  76.         cout << tByPrice.tours[i].country << '\n'
  77.             << tByPrice.tours[i].hotel_stars << '\n'
  78.             << tByPrice.tours[i].price << '\n';
  79.     }
  80.  
  81.  
  82. }
  83. void searchToursByPrice(Tour* toursByPrice,int& sizeByPrice,Tour* tours,int size, L price) {
  84.     for (int i = 0; i < size; i++) if (tours[i].price <= price) insert(toursByPrice, sizeByPrice, sizeByPrice, tours[i]);
  85.  
  86. }
  87. void deleteOutdatedTours(Tour* t,int& size) {
  88.     date cur_date = getCurDate();
  89.     for (int i = 0; i < size; i++) {
  90.         if (t[i].date_end.year < cur_date.year) {
  91.            erase(t,size,i); return;
  92.         }
  93.         else if (t[i].date_end.year == cur_date.year) {
  94.             if (t[i].date_end.month < cur_date.month) {
  95.                 erase(t, size, i); return;
  96.             }
  97.             else if (t[i].date_end.month == cur_date.month && t[i].date_end.day < cur_date.day) {
  98.                 erase(t, size, i); return;
  99.             }
  100.         }
  101.     }
  102. }
  103. date getCurDate() {
  104.     date d;
  105.     time_t rawtime;
  106.     struct tm* timeinfo;
  107.     char buffer[80];
  108.     time(&rawtime);
  109.     timeinfo = localtime(&rawtime);
  110.     strftime(buffer, sizeof(buffer), "%d", timeinfo);
  111.     d.day = atoi(buffer);
  112.     strftime(buffer, sizeof(buffer), "%m", timeinfo);
  113.     d.month = atoi(buffer);
  114.     strftime(buffer, sizeof(buffer), "%Y", timeinfo);
  115.     d.year = atoi(buffer);
  116.     return d;
  117. }
  118. void inputTour(Tour& t) {
  119.     cout << "Страна отдыха: "; cin >> t.country;
  120.     //cout << "Дата начала отдыха (формат Д,М,Г (через пробел 1 1 2022)): "; cin >> t.date_start.day >> t.date_start.month >> t.date_start.year;
  121.     cout << "Дата конца отдыха (формат Д,М,Г (через пробел 1 1 2022)): "; cin >> t.date_end.day >> t.date_end.month >> t.date_end.year;
  122.     cout << "Количество звезд у отеля: "; cin >> t.hotel_stars;
  123.     //cout << "Тип питания: \n"
  124.     //    << "1.Нет питания\n"
  125.     //    << "2.Все включено\n"
  126.     //    << "3.Шведский стол\n"
  127.     //    << "4.Завтрак в постелях\n"
  128.     //    << "Ваш ответ: ";
  129.     //unsigned short c;
  130.     //cin >> c;
  131.     //switch (c) {
  132.     //case 1:
  133.     //    t.type_eating = "Нет питания";
  134.     //    break;
  135.     //case 2:
  136.     //    t.type_eating = "Все включено";
  137.     //    break;
  138.     //case 3:
  139.     //    t.type_eating = "Шведский стол";
  140.     //    break;
  141.     //case 4:
  142.     //    t.type_eating = "Завтрак в постелях";
  143.     //    break;
  144.     //default:
  145.     //    cerr << "Такого варианта нет!";
  146.     //    return;
  147.     //}
  148.     //cout << "Вид отдыха: \n"
  149.     //    << "1.Пляжный\n"
  150.     //    << "2.Активный\n"
  151.     //    << "3.Экскурсионный\n"
  152.     //    << "Ваш ответ: ";
  153.     //cin >> c;
  154.     //switch (c) {
  155.     //case 1:
  156.     //    t.type_rest = "Пляжный";
  157.     //    break;
  158.     //case 2:
  159.     //    t.type_rest = "Активный";
  160.     //    break;
  161.     //case 3:
  162.     //    t.type_rest = "Экскурсионный";
  163.     //    break;
  164.     //default:
  165.     //    cerr << "Такого варианта нет!";
  166.     //    return;
  167.     //}
  168.     cout << "Цена отдыха: "; cin >> t.price;
  169. }
  170. void insertDataTour(Tour* tours, int& size, Tour t) {
  171.     if (tours==nullptr || size==0) {insert(tours,size,size,t); return; }
  172.     for (int i = 0; i < size; i++) {
  173.         if (tours[i].country == t.country) {
  174.             for (int j = i; j < size - 1; j++) {
  175.                 if (tours[j].country != tours[j + 1].country) {
  176.                     insert(tours,size, j + 1, t);
  177.                     return;
  178.                 }
  179.             }
  180.             insert(tours, size, size, t);
  181.             return;
  182.         }
  183.         else if (compareByCountry(t, tours[i])) {
  184.             insert(tours, size, i, t);
  185.             return;
  186.         }
  187.     }
  188.     insert(tours, size, size, t);
  189. }
  190. bool compareByCountry(const Tour a, const Tour b)
  191. {
  192.     for (int i = 0; i < min(a.country.size(), b.country.size()); i++) if (a.country[i] != b.country[i]) return (a.country[i] < b.country[i]);
  193.     return (a.country.size() < b.country.size());
  194. }
  195. void insert(Tour* arr, int& size, int pos, Tour el) {
  196.     size++;
  197.     for (int i = size-1; i > pos; i--) arr[i] = arr[i - 1];
  198.     arr[pos] = el;
  199. }
  200. void erase(Tour* arr, int& size, int pos) {
  201.     size--;
  202.     for (int i = pos; i < size; i++) arr[i] = arr[i + 1];
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement