spacerose

удалить потом

Oct 6th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4. #include <locale>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. struct los
  11. {
  12.     int employee;
  13.     int number;
  14.     int timefortask;
  15.     string info;
  16.     clock_t time;
  17.     los* next = NULL;
  18. };
  19.  
  20. struct ocher {
  21.     los* first = NULL;
  22.     los* last = NULL;
  23. };
  24.  
  25. struct ActionLos
  26. {
  27.     clock_t start = clock();
  28.     int BigTime;
  29.     int SizeList = 0;
  30.     ocher* q = new ocher;
  31.  
  32.     string command;
  33.     float number;
  34.     int size = 0;
  35.     void menu() {
  36.         cout << "Введите команды управления очередью:\nPUSH - добавление элементa\nPOP - удаление элемента из очереди и его вывод\nPRINT - вывод первого в очереди\nEMPTY - проверка пустоты очереди\nFULL - проверка полноты очереди\nEND - вывод элементов очереди и завершение работы\n\n";
  37.  
  38.         while (true)
  39.         {
  40.             cout << endl;
  41.             cin >> command;
  42.             if (command == "END")
  43.                 break;
  44.             else if (command == "PUSH")
  45.             {
  46.                 if (size < 7) {
  47.                     size++;
  48.  
  49.                     Push();
  50.                 }
  51.                 else
  52.                     cout << "Очередь переполнена! Добавление невозможно\n";
  53.             }
  54.             else if (command == "POP")
  55.             {
  56.                 if (size > 0) {
  57.                     size--;
  58.                     cout << Pop(qHead, qLast) << endl;
  59.                 }
  60.                 else
  61.                     cout << "Очередь пуста! Удаление невозможно\n";
  62.             }
  63.             else if (command == "PRINT")
  64.             {
  65.                 if (size > 0)
  66.                     cout << Print(qHead) << endl;
  67.                 else
  68.                     cout << "Очередь пуста! Вывод невозможен\n";
  69.             }
  70.             else if (command == "FULL")
  71.                 Full(size);
  72.             else if (command == "EMPTY")
  73.                 Empty(size);
  74.  
  75.             else
  76.                 cout << "Такой команды нет!\n";
  77.         }
  78.     }
  79.  
  80.     void conclusion() {
  81.         if (SizeList > 0) {
  82.             los* temprory = q->last;
  83.             cout << setw(15) << "приоритетность " << setw(18) << " номер сотрудника " << " информация о задании" << endl;
  84.  
  85.             while (temprory != NULL) {
  86.                 cout << setw(14) << temprory->employee;
  87.                 cout << setw(18) << temprory->number;
  88.                 cout << "  " << temprory->info << endl;
  89.  
  90.                 temprory = temprory->next;
  91.  
  92.             }
  93.         }
  94.         else {
  95.             cout << "Очередь пуста" << endl;
  96.         }
  97.     }
  98.  
  99.     void addElement() {
  100.         string s;
  101.         cout << "Введите категорию сотрудника (М, К или Р)" << endl;
  102.  
  103.         los* el = new los;
  104.         char category;
  105.         cin >> category;
  106.         switch (category) {
  107.         case 'M':
  108.             el->employee = 1;
  109.             break;
  110.         case 'P':
  111.             el->employee = 3;
  112.             break;
  113.         case 'K':
  114.             el->employee = 2;
  115.             break;
  116.         }
  117.  
  118.         cout << "Введите время выполнения задачи в секундах" << endl;
  119.         cin >> el->timefortask;
  120.  
  121.         cout << "Введите информацию о задаче" << endl;
  122.         cin >> el->info;
  123.  
  124.         cout << "Введите личный номер сотрудника" << endl;
  125.         cin >> el->number;
  126.  
  127.         el->time = clock();
  128.  
  129.         if (q->first == NULL) {
  130.             q->first = el;
  131.             q->last = el;
  132.             el->next = NULL;
  133.         }
  134.         else {
  135.             los* temprory = q->last;
  136.             while (temprory != NULL) {
  137.                 if (temprory->employee > el->employee
  138.                     && temprory->next != NULL &&
  139.                     temprory->next->employee <= el->employee) {
  140.                     el->next = temprory->next;
  141.                     temprory->next = el;
  142.                     break;
  143.                 }
  144.                 else if (temprory->employee > el->employee&& temprory->next == NULL) {
  145.                     q->first = el;
  146.                     temprory->next = el;
  147.                     el->next = NULL;
  148.                     break;
  149.                 }
  150.                 else if (temprory->employee <= el->employee) {
  151.                     q->last = el;
  152.                     el->next = temprory;
  153.                     break;
  154.                 }
  155.                 else if (temprory->employee < el->employee && temprory->next == NULL) {
  156.                     temprory->next = el;
  157.                     q->first = el;
  158.                     break;
  159.                 }
  160.                 temprory = temprory->next;
  161.  
  162.             }
  163.         }
  164.  
  165.         SizeList++;
  166.         cout << "Добавлено" << endl;
  167.  
  168.     }
  169.  
  170.     void deleteElement() {
  171.  
  172.         if (SizeList == 1) {
  173.             los* el = q->last;
  174.             BigTime = el->timefortask;
  175.             q->last = NULL;
  176.             q->first = NULL;
  177.             cout << "Заявка принята!" << endl;
  178.             cout << "Заявка находилась в очереди на рассмотрении " << (clock() - el->time) / 1000 << " секунд" << endl;
  179.             cout << "Информация о задании: " << el->info << endl;
  180.             cout << "Данное задание будет выполняться " << el->timefortask << " секунд" << endl;
  181.             delete el;
  182.         }
  183.         else {
  184.             los* el = q->first;
  185.             BigTime = el->timefortask;
  186.             los* current = q->last;
  187.             for (int i = 0; i < SizeList; i++) {
  188.                 if (current->next == el) {
  189.                     q->first = current;
  190.                     current->next = NULL;
  191.                     cout << "Заявка принята!" << endl;
  192.                     cout << "Заявка находилась в очереди на рассмотрении " << (clock() - el->time) / 1000 << " секунд" << endl;
  193.                     cout << "Информация о задании: " << el->info << endl;
  194.                     cout << "Данное задание будет выполняться " << el->timefortask << " секунд" << endl;
  195.  
  196.                     delete el;
  197.                     break;
  198.                 }
  199.                 current = current->next;
  200.             }
  201.         }
  202.         start = clock();
  203.         //cout << start << endl<<BigTime<<endl;
  204.  
  205.         SizeList--;
  206.  
  207.      
  208.     }
  209.  
  210.     void getValue() {
  211.         if (q->first != NULL) {
  212.             cout << "Приоритетность: " << q->first->employee << endl;
  213.             cout << "Номер сотрудника: " << q->first->number << endl;
  214.             cout << "Информация о задании: " << q->first->info << endl;
  215.             cout << "Время выполнения задания: " << q->first->timefortask << endl;
  216.         }
  217.         else {
  218.             cout << "Очередь пуста" << endl;
  219.         }
  220.      
  221.     }
  222.  
  223.     void isEmpty() {
  224.         if (q->first == NULL) {
  225.             cout << "Очередь пуста" << endl;
  226.         }
  227.         else cout << "Очередь не пуста" << endl;
  228.        
  229.     }
  230.  
  231.     void isFull() {
  232.         if (SizeList == 10) {
  233.             cout << "Очередь полна" << endl;
  234.         }
  235.         else {
  236.             cout << "Очередь не полна" << endl;
  237.         }
  238.        
  239.     }
  240. };
  241.  
  242. int main()
  243. {
  244.     SetConsoleCP(1251);
  245.     SetConsoleOutputCP(1251);
  246.     setlocale(LC_ALL, "");
  247.     ActionLos* work = new ActionLos;
  248.     work->menu();
  249.     return 0;
  250. }
  251.  
  252.  
  253.  
Advertisement
Add Comment
Please, Sign In to add comment