Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Задание 4-4
- // Обуховский Богдан 25.04.2020
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <map>
- using namespace std;
- //Правонарушение
- struct LowBreakTicket
- {
- int passID; //паспорт
- int placeID; //место
- int createdAt; //отметка времени
- static (LowBreakTicket* )
- };
- struct LowBreak
- {
- LowBreakTicket* ticket;
- LowBreak* next;
- LowBreak() { ticket = new LowBreakTicket; next = nullptr; };
- };
- struct LowBreaksList {
- LowBreak* begin;
- LowBreak* end;
- LowBreaksList() { begin = nullptr; end = nullptr; }
- void add(int tempPassID, int tempPlaceID, int time)
- {
- LowBreak* temp = new LowBreak;
- temp->ticket->passID = tempPassID;
- temp->ticket->placeID = tempPlaceID;
- temp->ticket->createdAt = time;
- if (begin == nullptr)
- {
- begin = temp;
- end = temp;
- }
- else
- {
- end->next = temp;
- end = temp;
- }
- }
- //вывод
- void print(int minTime = NULL, int maxTime = NULL)
- {
- cout << left << endl << "----- ПРАВОНАРУШЕНИЯ -------" << endl;
- LowBreak* temp = begin;
- while (temp != nullptr)
- {
- cout << "Нарушитель с паспрортом: " << setw(10) << temp->ticket->passID << "Место с кодом: " << setw(10) << temp->ticket->placeID << "Время: " << temp->ticket->createdAt << endl;
- temp = temp->next;
- }
- cout << "----- КОНЕЦ ПРАВОНАРУШЕНИЙ ------" << endl;
- }
- //вывод для промежутка
- void printInterval(int minTime, int maxTime)
- {
- cout << left << endl << "----- ПРАВОНАРУШЕНИЯ -------" << endl;
- cout << "-- с " << minTime << " по " << maxTime << " --" << endl;
- LowBreak* temp = begin;
- while (temp != nullptr)
- {
- if (temp->ticket->createdAt < minTime || temp->ticket->createdAt > maxTime)
- {
- if (temp->next == nullptr) break;
- temp = temp->next;
- continue;
- }
- cout << "Нарушитель с паспрортом: " << setw(10) << temp->ticket->passID << "Место с кодом: " << setw(10) << temp->ticket->placeID << "Время: " << temp->ticket->createdAt << endl;
- temp = temp->next;
- }
- cout << "----- КОНЕЦ ПРАВОНАРУШЕНИЙ ------" << endl;
- }
- };
- //место совместного пребывания
- struct Place
- {
- static const short DENIED = 0;
- static const short ALLOWED = 1;
- static map <short, string> status; //ключ-значение для статусов
- int id; //код
- int visiting; //посещаемоесть
- string name; //название
- bool isAllowToBeHere; //разрешено или запрещено
- Place* next; //следующее место
- Place() { visiting = 0; next = NULL; }
- };
- map <short, string> Place::status = {
- {0, "Запрещено для посещения"},
- {1, "Разрешено для посещения"}
- };
- struct PlaceList
- {
- Place* begin;
- Place* end;
- PlaceList() { begin = NULL; end = NULL; }
- void add(int id, string name, bool allow)
- {
- Place* temp = new Place;
- temp->id = id;
- temp->name = name;
- temp->isAllowToBeHere = allow;
- if (begin == NULL)
- {
- begin = temp;
- end = temp;
- }
- else
- {
- end->next = temp;
- end = temp;
- }
- }
- //вывод всех
- void printAll()
- {
- cout << endl << "--------- Все МСПр ---------" << endl << left;
- Place* temp = begin;
- while (temp != NULL)
- {
- cout << "Код места: " << setw(4) << temp->id << " ";
- cout << "Название: " << setw(20) << temp->name << " ";
- cout << "Статус: " << Place::status[temp->isAllowToBeHere] << endl;
- temp = temp->next;
- }
- cout << "------- Конец списка -------" << endl << setw('\0');
- }
- };
- //житель
- struct Citizen
- {
- const short WORK_DENIED = 0; //запрещено работать
- const short WORK_ALLOW = 1; //разрешено работать
- static map <short, string> workStatusList; //ключ-значение для статусов
- const bool HEALTHY = 0; //здоров
- const bool ILL = 1; //болеет
- static map <bool, string> healthStatusList; //ключ-значение для статусов
- int id; //номер паспорта
- int lowBreakCount; //количество правонарушений
- int age;
- string firstName; //имя
- string middleName; //отчество
- string lastName; //фамилия
- bool healthStatus; //состояние здоровья
- bool workStaus; //разрешена ли работа
- Citizen* next; //следующий житель
- Citizen() { lowBreakCount = 0; next = NULL; };
- };
- map <short, string> Citizen::workStatusList = {
- {0, "Запрещено работать"},
- {1, "Разрешено работать"}
- };
- map <bool, string> Citizen::healthStatusList = {
- {0, "Здоров"},
- {1, "Болеет"}
- };
- struct CitizensList
- {
- Citizen* begin;
- Citizen* end;
- CitizensList() { begin = NULL; end = NULL; }
- void add(int id, int age, string lastName, string firstName, string middleName, bool health, bool work)
- {
- Citizen* temp = new Citizen;
- temp->id = id;
- temp->age = age;
- temp->lastName = lastName;
- temp->firstName = firstName;
- temp->middleName = middleName;
- temp->healthStatus = health;
- temp->workStaus = work;
- if (begin == NULL)
- {
- begin = temp;
- end = temp;
- }
- else
- {
- end->next = temp;
- end = temp;
- }
- }
- //вывод всех
- void printAll()
- {
- cout << endl << "--------- Все жители ---------" << endl << left;
- Citizen* temp = begin;
- while (temp != NULL)
- {
- cout << "Паспорт: " << setw(10) << temp->id << " ";
- cout << "ФИО: " << setw(15) << temp->lastName << " " << setw(10) << temp->firstName << " " << setw(15) << temp->middleName << " ";
- cout << "Возраст: " << setw(3) << temp->age << " ";
- cout << "Статус здоровья: " << Citizen::healthStatusList[temp->healthStatus] << " ";
- cout << "Работа: " << Citizen::workStatusList[temp->workStaus] << endl;
- temp = temp->next;
- }
- cout << "------- Конец списка -------" << endl << setw('\0');
- }
- //вывод по группе риска
- void printOldest()
- {
- cout << endl << "----- Группа риска по возрасту (45+ лет) -----" << endl;
- Citizen* temp = begin;
- while (temp != NULL)
- {
- if (temp->age < 45)
- {
- if (temp->next == nullptr) break;
- temp = temp->next;
- continue;
- }
- cout << "Паспорт: " << setw(10) << temp->id << " ";
- cout << "ФИО: " << setw(15) << temp->lastName << " " << setw(10) << temp->firstName << " " << setw(15) << temp->middleName << " ";
- cout << "Возраст: " << setw(3) << temp->age << " ";
- cout << "Статус здоровья: " << Citizen::healthStatusList[temp->healthStatus] << " ";
- cout << "Работа: " << Citizen::workStatusList[temp->workStaus] << endl;
- temp = temp->next;
- }
- cout << "----- КОНЕЦ СПИСКА -----" << endl;
- }
- };
- //совершить передвижение
- void makeMovement(int passID, int placeID, int time);
- //Заполнить места из файла, формат:
- //id name isAllowToBeHere
- //Например:
- //201 Больница 1
- //202 Парк 0
- void fillPlacesFromFile(PlaceList* places)
- {
- ifstream f;
- f.open("МСПр.txt");
- while (!f.eof())
- {
- int tempId;
- string tempName;
- bool tempAllow;
- f >> tempId >> tempName >> tempAllow;
- places->add(tempId, tempName, tempAllow);
- }
- f.close();
- }
- //Заполнить жителей из файла, формат:
- //id lastName firstName middleName healthStatus workStaus
- //Например:
- //1924946290 Обуховский Богдан Игоревич 0 0
- void fillCitizensFromFile(CitizensList* citizens)
- {
- ifstream f;
- f.open("Жители.txt");
- while (!f.eof())
- {
- int tempId, tempAge;
- string tempFName, tempMName, tempLName;
- bool tempHealth, tempWork;
- f >> tempId >> tempAge >> tempLName >> tempFName >> tempMName >> tempHealth >> tempWork;
- citizens->add(tempId, tempAge, tempLName, tempFName, tempMName, tempHealth, tempWork);
- }
- f.close();
- }
- int main()
- {
- setlocale(0, "rus"); // Подключение русского языка
- LowBreaksList* lowBreaks = new LowBreaksList; //правонарушения
- CitizensList* S = new CitizensList; //жители
- PlaceList* W = new PlaceList; //места
- fillPlacesFromFile(W);
- W->printAll();
- fillCitizensFromFile(S);
- S->printAll();
- S->printOldest();
- int cID, pID, time;
- cout << "Зарегистрировать правонарушение (номер паспорта, номер места, время): ";
- cin >> cID >> pID >> time;
- lowBreaks->add(cID, pID, time);
- cout << "Зарегистрировать правонарушение (номер паспорта, номер места, время): ";
- cin >> cID >> pID >> time;
- lowBreaks->add(cID, pID, time);
- cout << "Зарегистрировать правонарушение (номер паспорта, номер места, время): ";
- cin >> cID >> pID >> time;
- lowBreaks->add(cID, pID, time);
- lowBreaks->print(); //вывод всех
- lowBreaks->printInterval(3, 5); //вывод по интервалу
- system("pause");
- return 0;
- }
- void makeMovement(int passID, int placeID, int time) {
- }
Advertisement
Add Comment
Please, Sign In to add comment