bogdan_obukhovskii

mainCPP

Apr 25th, 2020
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.55 KB | None | 0 0
  1. // Задание 4-4
  2. // Обуховский Богдан 25.04.2020
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <iomanip>
  7. #include <map>
  8.  
  9. using namespace std;
  10.  
  11. //Правонарушение
  12. struct LowBreakTicket
  13. {
  14.     int passID;  //паспорт
  15.     int placeID; //место
  16.  
  17.     int createdAt; //отметка времени
  18.  
  19.     static (LowBreakTicket* )
  20. };
  21.  
  22. struct LowBreak
  23. {
  24.     LowBreakTicket* ticket;
  25.  
  26.     LowBreak* next;
  27.  
  28.     LowBreak() { ticket = new LowBreakTicket; next = nullptr; };
  29. };
  30.  
  31. struct LowBreaksList {
  32.     LowBreak* begin;
  33.     LowBreak* end;
  34.  
  35.     LowBreaksList() { begin = nullptr; end = nullptr; }
  36.  
  37.     void add(int tempPassID, int tempPlaceID, int time)
  38.     {
  39.         LowBreak* temp = new LowBreak;
  40.         temp->ticket->passID = tempPassID;
  41.         temp->ticket->placeID = tempPlaceID;
  42.         temp->ticket->createdAt = time;
  43.  
  44.         if (begin == nullptr)
  45.         {
  46.             begin = temp;
  47.             end = temp;
  48.         }
  49.         else
  50.         {
  51.             end->next = temp;
  52.             end = temp;
  53.         }
  54.     }
  55.  
  56.     //вывод
  57.     void print(int minTime = NULL, int maxTime = NULL)
  58.     {
  59.         cout << left << endl << "----- ПРАВОНАРУШЕНИЯ -------" << endl;
  60.         LowBreak* temp = begin;
  61.         while (temp != nullptr)
  62.         {
  63.             cout << "Нарушитель с паспрортом: " << setw(10) << temp->ticket->passID << "Место с кодом: " << setw(10) << temp->ticket->placeID << "Время: " << temp->ticket->createdAt << endl;
  64.             temp = temp->next;
  65.         }
  66.         cout << "----- КОНЕЦ ПРАВОНАРУШЕНИЙ ------" << endl;
  67.     }
  68.  
  69.     //вывод для промежутка
  70.     void printInterval(int minTime, int maxTime)
  71.     {
  72.         cout << left << endl << "----- ПРАВОНАРУШЕНИЯ -------" << endl;
  73.         cout << "-- с " << minTime << " по " << maxTime << " --" << endl;
  74.         LowBreak* temp = begin;
  75.         while (temp != nullptr)
  76.         {
  77.             if (temp->ticket->createdAt < minTime || temp->ticket->createdAt > maxTime)
  78.             {
  79.                 if (temp->next == nullptr) break;
  80.  
  81.                 temp = temp->next;
  82.                 continue;
  83.             }
  84.  
  85.             cout << "Нарушитель с паспрортом: " << setw(10) << temp->ticket->passID << "Место с кодом: " << setw(10) << temp->ticket->placeID << "Время: " << temp->ticket->createdAt << endl;
  86.             temp = temp->next;
  87.         }
  88.         cout << "----- КОНЕЦ ПРАВОНАРУШЕНИЙ ------" << endl;
  89.     }
  90. };
  91.  
  92. //место совместного пребывания
  93. struct Place
  94. {
  95.     static const short DENIED  = 0;
  96.     static const short ALLOWED = 1;
  97.     static map <short, string> status; //ключ-значение для статусов
  98.  
  99.     int id;             //код
  100.     int visiting;        //посещаемоесть
  101.  
  102.     string name;          //название
  103.     bool isAllowToBeHere; //разрешено или запрещено
  104.  
  105.     Place* next; //следующее место
  106.  
  107.     Place() { visiting = 0; next = NULL; }
  108. };
  109.  
  110. map <short, string> Place::status = {
  111.         {0, "Запрещено для посещения"},
  112.         {1, "Разрешено для посещения"}
  113. };
  114.  
  115. struct PlaceList
  116. {
  117.     Place* begin;
  118.     Place* end;
  119.  
  120.     PlaceList() { begin = NULL; end = NULL; }
  121.  
  122.     void add(int id, string name, bool allow)
  123.     {
  124.         Place* temp = new Place;
  125.         temp->id = id;
  126.         temp->name = name;
  127.         temp->isAllowToBeHere = allow;
  128.  
  129.         if (begin == NULL)
  130.         {
  131.             begin = temp;
  132.             end = temp;
  133.         }
  134.         else
  135.         {
  136.             end->next = temp;
  137.             end = temp;
  138.         }
  139.     }
  140.  
  141.     //вывод всех
  142.     void printAll()
  143.     {
  144.         cout << endl << "---------  Все МСПр  ---------" << endl << left;
  145.  
  146.         Place* temp = begin;
  147.  
  148.         while (temp != NULL)
  149.         {
  150.             cout << "Код места: " << setw(4) << temp->id << " ";
  151.             cout << "Название: " << setw(20) << temp->name << " ";
  152.             cout << "Статус: " << Place::status[temp->isAllowToBeHere] << endl;
  153.             temp = temp->next;
  154.         }
  155.         cout << "------- Конец списка -------" << endl << setw('\0');
  156.     }
  157. };
  158.  
  159. //житель
  160. struct Citizen
  161. {
  162.     const short WORK_DENIED = 0; //запрещено работать
  163.     const short WORK_ALLOW  = 1; //разрешено работать
  164.     static map <short, string> workStatusList; //ключ-значение для статусов
  165.  
  166.     const bool HEALTHY = 0; //здоров
  167.     const bool ILL     = 1; //болеет
  168.     static map <bool, string> healthStatusList; //ключ-значение для статусов
  169.  
  170.     int id;            //номер паспорта
  171.     int lowBreakCount; //количество правонарушений
  172.     int age;
  173.  
  174.     string firstName;  //имя
  175.     string middleName; //отчество
  176.     string lastName;   //фамилия
  177.  
  178.     bool healthStatus; //состояние здоровья
  179.     bool workStaus;    //разрешена ли работа
  180.  
  181.     Citizen* next; //следующий житель
  182.  
  183.     Citizen() { lowBreakCount = 0; next = NULL; };
  184.  
  185. };
  186.  
  187. map <short, string> Citizen::workStatusList = {
  188.     {0, "Запрещено работать"},
  189.     {1, "Разрешено работать"}
  190. };
  191.  
  192. map <bool, string> Citizen::healthStatusList = {
  193.     {0, "Здоров"},
  194.     {1, "Болеет"}
  195. };
  196.  
  197. struct CitizensList
  198. {
  199.     Citizen* begin;
  200.     Citizen* end;
  201.  
  202.     CitizensList() { begin = NULL; end = NULL; }
  203.  
  204.     void add(int id, int age, string lastName, string firstName, string middleName, bool health, bool work)
  205.     {
  206.         Citizen* temp = new Citizen;
  207.         temp->id = id;
  208.         temp->age = age;
  209.         temp->lastName = lastName;
  210.         temp->firstName = firstName;
  211.         temp->middleName = middleName;
  212.         temp->healthStatus = health;
  213.         temp->workStaus = work;
  214.  
  215.         if (begin == NULL)
  216.         {
  217.             begin = temp;
  218.             end = temp;
  219.         }
  220.         else
  221.         {
  222.             end->next = temp;
  223.             end = temp;
  224.         }
  225.     }
  226.  
  227.     //вывод всех
  228.     void printAll()
  229.     {
  230.         cout << endl << "---------  Все жители  ---------" << endl << left;
  231.  
  232.         Citizen* temp = begin;
  233.  
  234.         while (temp != NULL)
  235.         {
  236.             cout << "Паспорт: " << setw(10) << temp->id << " ";
  237.             cout << "ФИО: " << setw(15) << temp->lastName << " " << setw(10) << temp->firstName << " " << setw(15) << temp->middleName << "      ";
  238.             cout << "Возраст: " << setw(3) << temp->age << "      ";
  239.             cout << "Статус здоровья: " << Citizen::healthStatusList[temp->healthStatus] << "     ";
  240.             cout << "Работа: " << Citizen::workStatusList[temp->workStaus] << endl;
  241.             temp = temp->next;
  242.         }
  243.         cout << "------- Конец списка -------" << endl << setw('\0');
  244.     }
  245.  
  246.     //вывод по группе риска
  247.     void printOldest()
  248.     {
  249.         cout << endl << "----- Группа риска по возрасту (45+ лет) -----" << endl;
  250.  
  251.         Citizen* temp = begin;
  252.  
  253.         while (temp != NULL)
  254.         {
  255.             if (temp->age < 45)
  256.             {
  257.                 if (temp->next == nullptr) break;
  258.  
  259.                 temp = temp->next;
  260.                 continue;
  261.             }
  262.             cout << "Паспорт: " << setw(10) << temp->id << " ";
  263.             cout << "ФИО: " << setw(15) << temp->lastName << " " << setw(10) << temp->firstName << " " << setw(15) << temp->middleName << "      ";
  264.             cout << "Возраст: " << setw(3) << temp->age << "      ";
  265.             cout << "Статус здоровья: " << Citizen::healthStatusList[temp->healthStatus] << "     ";
  266.             cout << "Работа: " << Citizen::workStatusList[temp->workStaus] << endl;
  267.             temp = temp->next;
  268.         }
  269.         cout << "-----    КОНЕЦ СПИСКА    -----" << endl;
  270.     }
  271. };
  272.  
  273. //совершить передвижение
  274. void makeMovement(int passID, int placeID, int time);
  275.  
  276. //Заполнить места из файла, формат:
  277. //id name isAllowToBeHere
  278. //Например:
  279. //201 Больница 1
  280. //202 Парк 0
  281. void fillPlacesFromFile(PlaceList* places)
  282. {
  283.     ifstream f;
  284.     f.open("МСПр.txt");
  285.  
  286.     while (!f.eof())
  287.     {
  288.         int tempId;
  289.         string tempName;
  290.         bool tempAllow;
  291.  
  292.         f >> tempId >> tempName >> tempAllow;
  293.         places->add(tempId, tempName, tempAllow);
  294.     }
  295.  
  296.     f.close();
  297. }
  298.  
  299. //Заполнить жителей из файла, формат:
  300. //id lastName firstName middleName healthStatus workStaus
  301. //Например:
  302. //1924946290 Обуховский Богдан Игоревич 0 0
  303. void fillCitizensFromFile(CitizensList* citizens)
  304. {
  305.     ifstream f;
  306.     f.open("Жители.txt");
  307.     while (!f.eof())
  308.     {
  309.         int tempId, tempAge;
  310.         string tempFName, tempMName, tempLName;
  311.         bool tempHealth, tempWork;
  312.  
  313.         f >> tempId >> tempAge >> tempLName >> tempFName >> tempMName >> tempHealth >> tempWork;
  314.         citizens->add(tempId, tempAge, tempLName, tempFName, tempMName, tempHealth, tempWork);
  315.     }
  316.     f.close();
  317. }
  318.  
  319. int main()
  320. {
  321.     setlocale(0, "rus"); // Подключение русского языка
  322.  
  323.     LowBreaksList* lowBreaks = new LowBreaksList; //правонарушения
  324.  
  325.     CitizensList*  S = new CitizensList;        //жители
  326.     PlaceList*     W = new PlaceList;        //места
  327.  
  328.     fillPlacesFromFile(W);
  329.     W->printAll();
  330.  
  331.     fillCitizensFromFile(S);
  332.     S->printAll();
  333.     S->printOldest();
  334.    
  335.  
  336.     int cID, pID, time;
  337.  
  338.     cout << "Зарегистрировать правонарушение (номер паспорта, номер места, время): ";
  339.     cin >> cID >> pID >> time;
  340.     lowBreaks->add(cID, pID, time);
  341.  
  342.     cout << "Зарегистрировать правонарушение (номер паспорта, номер места, время): ";
  343.     cin >> cID >> pID >> time;
  344.     lowBreaks->add(cID, pID, time);
  345.  
  346.     cout << "Зарегистрировать правонарушение (номер паспорта, номер места, время): ";
  347.     cin >> cID >> pID >> time;
  348.     lowBreaks->add(cID, pID, time);
  349.  
  350.     lowBreaks->print();             //вывод всех
  351.     lowBreaks->printInterval(3, 5); //вывод по интервалу
  352.  
  353.     system("pause");
  354.     return 0;
  355. }
  356.  
  357. void makeMovement(int passID, int placeID, int time) {
  358.  
  359. }
Advertisement
Add Comment
Please, Sign In to add comment