Advertisement
SillyWolfy

lab 14

May 25th, 2024
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.61 KB | None | 0 0
  1. #define NOMINMAX
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <string>
  5. #include <limits>
  6. #include <fstream>
  7. #include <sstream>
  8. #include <vector>
  9. using namespace std;
  10.  
  11. struct Coach;
  12. struct Gym
  13. {
  14.     string name;
  15.     vector<Coach*> coaches;
  16. };
  17.  
  18. struct Coach
  19. {
  20.     string name;
  21.     vector<Gym*> gyms;
  22. };
  23.  
  24. void make_relation(vector<Gym>& gyms, vector<Coach>& coaches) {
  25.     system("cls");
  26.     if (coaches.empty()) {
  27.         cout << "Нет тренеров для связи.\n";
  28.         system("pause");
  29.         system("cls");
  30.         return;
  31.     }
  32.     if (gyms.empty()) {
  33.         cout << "Нет залов для связи.\n";
  34.         system("pause");
  35.         system("cls");
  36.         return;
  37.     }
  38.     int indx = 0;
  39.     for (auto& i : coaches)
  40.     {
  41.         cout << indx + 1 << ". " << i.name << '\n';
  42.         indx++;
  43.     }
  44.     int coach_indx = 0;
  45.     while (true) {
  46.         cout << "Выберите тренера для связи: ";
  47.         if (cin >> coach_indx and coach_indx > 0 and coach_indx <= coaches.size()) {
  48.             break;
  49.         }
  50.         else {
  51.             cout << "Неверный ввод. Попробуйте снова.\n";
  52.             cin.clear();
  53.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  54.         }
  55.     }
  56.  
  57.     indx = 0;
  58.     for (auto& i : gyms)
  59.     {
  60.         cout << indx + 1 << ". " << i.name << '\n';
  61.         indx++;
  62.     }
  63.     int gym_indx = 0;
  64.     while (true) {
  65.         cout << "Выберите зал для связи: ";
  66.         if (cin >> gym_indx and gym_indx > 0 and gym_indx <= gyms.size()) {
  67.             break;
  68.         }
  69.         else {
  70.             cout << "Неверный ввод. Попробуйте снова.\n";
  71.             cin.clear();
  72.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  73.         }
  74.     }
  75.  
  76.     gyms[gym_indx - 1].coaches.push_back(&coaches[coach_indx - 1]);
  77.     coaches[coach_indx - 1].gyms.push_back(&gyms[gym_indx - 1]);
  78.     system("cls");
  79. }
  80.  
  81. void add_coach(vector<Coach>& coaches) {
  82.     system("cls");
  83.     Coach new_coach;
  84.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  85.     cout << "Введите имя тренера: ";
  86.     string name;
  87.     getline(cin, name);
  88.     new_coach.name = name;
  89.     coaches.push_back(new_coach);
  90.     system("cls");
  91. }
  92.  
  93. void add_gym(vector<Gym>& gyms) {
  94.     system("cls");
  95.     Gym new_gym;
  96.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  97.     cout << "Введите название зала: ";
  98.     string name;
  99.     getline(cin, name);
  100.     new_gym.name = name;
  101.     gyms.push_back(new_gym);
  102.     system("cls");
  103. }
  104.  
  105. void list_gyms(const vector<Gym>& gyms) {
  106.     system("cls");
  107.     if (gyms.empty()) {
  108.         cout << "Список залов пуст.\n";
  109.     }
  110.     else {
  111.         for (const auto& gym : gyms) {
  112.             cout << gym.name << '\n';
  113.         }
  114.     }
  115.     system("pause");
  116.     system("cls");
  117. }
  118.  
  119. void list_coaches(const vector<Coach>& coaches) {
  120.     system("cls");
  121.     if (coaches.empty()) {
  122.         cout << "Список тренеров пуст.\n";
  123.     }
  124.     else {
  125.         for (const auto& coach : coaches) {
  126.             cout << coach.name << '\n';
  127.         }
  128.     }
  129.     system("pause");
  130.     system("cls");
  131. }
  132.  
  133. void list_coaches_in_gym(const vector<Gym>& gyms) {
  134.     system("cls");
  135.     if (gyms.empty()) {
  136.         cout << "Список залов пуст.\n";
  137.         system("pause");
  138.         system("cls");
  139.         return;
  140.     }
  141.     int indx = 0;
  142.     for (const auto& gym : gyms) {
  143.         cout << indx + 1 << ". " << gym.name << '\n';
  144.         indx++;
  145.     }
  146.     int gym_indx = 0;
  147.     while (true) {
  148.         cout << "Выберите зал для отображения тренеров: ";
  149.         if (cin >> gym_indx and gym_indx > 0 and gym_indx <= gyms.size()) {
  150.             break;
  151.         }
  152.         else {
  153.             cout << "Неверный ввод. Попробуйте снова.\n";
  154.             cin.clear();
  155.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  156.         }
  157.     }
  158.  
  159.     system("cls");
  160.     if (gyms[gym_indx - 1].coaches.empty()) {
  161.         cout << "В этом зале нет тренеров.\n";
  162.     }
  163.     else {
  164.         for (const auto& coach : gyms[gym_indx - 1].coaches) {
  165.             cout << coach->name << '\n';
  166.         }
  167.     }
  168.     system("pause");
  169.     system("cls");
  170. }
  171.  
  172. void list_gyms_of_coach(const vector<Coach>& coaches) {
  173.     system("cls");
  174.     if (coaches.empty()) {
  175.         cout << "Список тренеров пуст.\n";
  176.         system("pause");
  177.         system("cls");
  178.         return;
  179.     }
  180.     int indx = 0;
  181.     for (const auto& coach : coaches) {
  182.         cout << indx + 1 << ". " << coach.name << '\n';
  183.         indx++;
  184.     }
  185.     int coach_indx = 0;
  186.     while (true) {
  187.         cout << "Выберите тренера для отображения залов: ";
  188.         if (cin >> coach_indx and coach_indx > 0 and coach_indx <= coaches.size()) {
  189.             break;
  190.         }
  191.         else {
  192.             cout << "Неверный ввод. Попробуйте снова.\n";
  193.             cin.clear();
  194.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  195.         }
  196.     }
  197.  
  198.     system("cls");
  199.     if (coaches[coach_indx - 1].gyms.empty()) {
  200.         cout << "У этого тренера нет залов.\n";
  201.     }
  202.     else {
  203.         for (const auto& gym : coaches[coach_indx - 1].gyms) {
  204.             cout << gym->name << '\n';
  205.         }
  206.     }
  207.     system("pause");
  208.     system("cls");
  209. }
  210.  
  211. int main()
  212. {
  213.     SetConsoleOutputCP(1251);
  214.     SetConsoleCP(1251);
  215.     setlocale(LC_ALL, "Russian");
  216.     vector<Gym> my_gyms;
  217.     vector<Coach> my_coaches;
  218.     while (true)
  219.     {
  220.         cout << "--------------------\n";
  221.         cout << "Выберите один из пунктов меню\n";
  222.         cout << "1) Создать связь\n"
  223.             << "2) Добавить тренера\n"
  224.             << "3) Добавить зал\n"
  225.             << "4) Список залов\n"
  226.             << "5) Список тренеров\n"
  227.             << "6) Вывести всех тренеров из зала\n"
  228.             << "7) Вывести все залы тренера\n"
  229.             << "8) Закончить программу\n"
  230.             << "Введите нужный пункт меню: ";
  231.         int answer;
  232.         while (true) {
  233.             if (cin >> answer and answer > 0 and answer <= 8) {
  234.                 break;
  235.             }
  236.             else {
  237.                 cout << "Неверный ввод. Попробуйте снова.\n";
  238.                 cin.clear();
  239.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  240.             }
  241.         }
  242.         switch (answer)
  243.         {
  244.         case 1: {
  245.             make_relation(my_gyms, my_coaches);
  246.             break;
  247.         }
  248.         case 2: {
  249.             add_coach(my_coaches);
  250.             break;
  251.         }
  252.         case 3: {
  253.             add_gym(my_gyms);
  254.             break;
  255.         }
  256.         case 4: {
  257.             list_gyms(my_gyms);
  258.             break;
  259.         }
  260.         case 5: {
  261.             list_coaches(my_coaches);
  262.             break;
  263.         }
  264.         case 6: {
  265.             list_coaches_in_gym(my_gyms);
  266.             break;
  267.         }
  268.         case 7: {
  269.             list_gyms_of_coach(my_coaches);
  270.             break;
  271.         }
  272.         case 8: {
  273.             return 0;
  274.         }
  275.         default:
  276.             cout << "Неверный пункт меню, попробуйте снова.\n";
  277.             system("pause");
  278.             system("cls");
  279.             break;
  280.         }
  281.     }
  282. }
  283.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement