Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <sstream>
- #include <windows.h>
- using namespace std;
- struct Info
- {
- string last_name;
- string first_name;
- string patronymic;
- int personnel_number;
- int experience;
- int salary;
- string specialty;
- };
- struct List
- {
- Info detail;
- List* next;
- List* prev;
- };
- List* head = NULL;
- List* last = NULL;
- void displayMembers(List* h)
- {
- cout << "|------------------------------------------------------------------------------------------------------------------|\n"
- << "| "
- << setw(12) << left << "Фамилия" << " | "
- << setw(12) << left << "Имя" << " | "
- << setw(12) << left << "Отчество" << " | "
- << setw(15) << "Табельный номер" << " | "
- << setw(8) << "Опыт" << " | "
- << setw(12) << "Оклад" << " | "
- << setw(23) << left << "Специальность" << " |\n"
- << "|------------------------------------------------------------------------------------------------------------------|\n";
- for (List* temp = h; temp; temp = temp->next) {
- cout << "| "
- << setw(12) << left << temp->detail.last_name << " | "
- << setw(12) << left << temp->detail.first_name << " | "
- << setw(12) << left << temp->detail.patronymic << " | "
- << setw(15) << temp->detail.personnel_number << " | "
- << setw(8) << temp->detail.experience << " | "
- << setw(12) << temp->detail.salary << " | "
- << setw(23) << left << temp->detail.specialty << " |\n";
- }
- cout << "|------------------------------------------------------------------------------------------------------------------|\n\n";
- }
- void addByPersonnelNumber(Info worker)
- {
- List* search = head;
- List* temp = new List;
- temp->detail = worker;
- temp->next = NULL;
- if (search == NULL) {
- head = temp;
- return;
- }
- if (search->detail.personnel_number >= worker.personnel_number) {
- List* newList = new List;
- newList->detail = worker;
- newList->next = head;
- head = newList;
- return;
- }
- while (search->next != NULL) {
- if (search->next->detail.personnel_number >= worker.personnel_number) {
- List* newList = new List;
- newList->detail = worker;
- newList->next = search->next;
- search->next = newList;
- return;
- }
- search = search->next;
- }
- for (List* temp1 = head; temp1; temp1 = temp1->next) {
- if (temp1->next == NULL) {
- temp1->next = temp;
- return;
- }
- }
- }
- void addMemberLast(List*& h, List*& l, Info worker)
- {
- List* member = new List;
- member->detail.last_name = worker.last_name;
- member->detail.first_name = worker.first_name;
- member->detail.patronymic = worker.patronymic;
- member->detail.personnel_number = worker.personnel_number;
- member->detail.experience = worker.experience;
- member->detail.salary = worker.salary;
- member->detail.specialty = worker.specialty;
- if (l == NULL) {
- h = member;
- member->prev = NULL;
- member->next = NULL;
- l = member;
- }
- else {
- member->prev = l;
- l->next = member;
- member->next = NULL;
- l = member;
- }
- }
- void addMember()
- {
- Info worker;
- cout << "Введите информацию о рабочем в виде:\nФамилия Имя Отчество Табельный_номер Опыт Оклад Специальность\n";
- while (!((cin >> worker.last_name >> worker.first_name >> worker.patronymic >> worker.personnel_number >> worker.experience >> worker.salary >> worker.specialty) || (cin.peek() != '\n'))
- && worker.personnel_number && worker.experience >= 0 && worker.salary >= 0) {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Неверный ввод\n";
- }
- addByPersonnelNumber(worker);
- system("cls");
- displayMembers(head);
- }
- void removeByPersonnelNumber(int personnel_number)
- {
- List* del = head;
- if (del == NULL)
- {
- return;
- }
- if (del->detail.personnel_number == personnel_number)
- {
- head = del->next;
- removeByPersonnelNumber(personnel_number);
- return;
- }
- if (del->next == NULL)
- {
- return;
- }
- while (del->next != NULL)
- {
- if (del->next->detail.personnel_number == personnel_number)
- {
- del->next = del->next->next;
- removeByPersonnelNumber(personnel_number);
- return;
- }
- del = del->next;
- }
- }
- void deleteMember()
- {
- int personnel_number;
- cout << "Список рабочих:\n"; displayMembers(head);
- cout << "Введите табельный номер рабочего, которого вы хотите удалить\n";
- while (!(cin >> personnel_number) || (cin.peek() != '\n') || personnel_number < 1) {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Неверный ввод\n";
- }
- removeByPersonnelNumber(personnel_number);
- system("cls");
- displayMembers(head);
- }
- void displayMembersListWithParameters()
- {
- List* t_head = NULL;
- List* t_last = NULL;
- int x, y;
- string specialty;
- cout << "Введите границы поиска в виде x y: ";
- while (!(cin >> x >> y) || (cin.peek() != '\n')) {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Неверный ввод\n";
- }
- cout << "Введите специальность: ", cin >> specialty;
- for (List* temp = head; temp; temp = temp->next) {
- if ((temp->detail.experience >= x && temp->detail.experience <= y) && temp->detail.specialty == specialty) {
- addMemberLast(t_head, t_last, temp->detail);
- }
- }
- system("cls");
- displayMembers(t_head);
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- setlocale(LC_ALL, ".1251");
- addMember();
- system("cls");
- displayMembers(head);
- while (true) {
- int choice;
- cout << "1. Список рабочих\n"
- << "2. Добавить рабочего\n"
- << "3. Удалить рабочего\n"
- << "4. Вывод рабочих с заданными пределами стажа и специальностью\n"
- << "5. Выход из программы\n";
- while (!(cin >> choice) || (cin.peek() != '\n')) {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Неверный ввод\n";
- }
- switch (choice) {
- case 1:
- system("cls");
- displayMembers(head);
- break;
- case 2:
- system("cls");
- addMember();
- break;
- case 3:
- system("cls");
- deleteMember();
- break;
- case 4:
- system("cls");
- displayMembersListWithParameters();
- break;
- case 5:
- return 0;
- default:
- system("cls");
- cout << "Неверное число\n";
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement