Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include "Human.h"
- #include "Tourist.h"
- #include "Businessman.h"
- #include "Business.h"
- #include "MyFile.h"
- bool compare1(Human first, Human second)
- {
- if (first.getSurname() < second.getSurname())
- return true;
- return false;
- }
- bool compare2(Human first, Human second)
- {
- if (first.getName() < second.getName())
- return true;
- return false;
- }
- bool compare3(Human first, Human second)
- {
- if (first.getYearBirth() < second.getYearBirth())
- return true;
- return false;
- }
- bool compare4(Human first, string surname)
- {
- if (first.getSurname() == surname)
- return true;
- return false;
- }
- bool compare5(Human first, string name)
- {
- if (first.getName() == name)
- return true;
- return false;
- }
- bool compare6(Human first, int year)
- {
- if (first.getYearBirth() == year)
- return true;
- return false;
- }
- using namespace std;
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- MyFile f;
- f.open("file.txt", MyFile::Binary);
- int size = 2;
- Queue<Human> humans;
- Human tmp;
- while(1)
- {
- system("cls");
- cout << " 1 - Ввести элемент" << endl;
- cout << " 2 - Показать таблицу" << endl;
- cout << " 3 - Удалить элемент" << endl;
- cout << " 4 - Поиск" << endl;
- cout << " 5 - Отсортировать" << endl;
- cout << " 6 - Записать в файл" << endl;
- cout << " 0 - Выйти" << endl;
- cout << " Выберите команду:";
- cin.sync();
- switch(cin.get())
- {
- case '1' :
- {
- system("cls");
- do
- {
- cin >> tmp;
- humans.push(tmp);
- cout << "Введите любой символ, чтобы продолжить ввод?(0 - выйти)";
- getchar();
- if (cin.get() == '0') break;
- cin.sync();
- }while(1);
- break;
- }
- case '2' :
- {
- system("cls");
- if (!humans.begin())
- {
- cout << "нет информации" << endl;
- system("pause");
- continue;
- }
- humans[0].table();
- for (Queue<Human>::Iterator i = humans.begin(); i != humans.end(); i++)
- {
- Human temp = *i;
- cout << temp << endl;
- }
- system("pause");
- break;
- }
- case '3' :
- {
- system("cls");
- humans.node_delete();
- system("pause");
- break;
- }
- case '4':
- {
- system("cls");
- Queue<Human> tempQue;
- tempQue = humans;
- Node<Human> *tempNode;
- do
- {
- system("cls");
- cout << " 1 - Фамилия" << endl;
- cout << " 2 - Имя" << endl;
- cout << " 3 - Год рождения" << endl;
- cout << " 4 - Показать результат" << endl;
- int i;
- cin >> i;
- if (i == 1)
- {
- cout << " Введите фамилию: ";
- string surname;
- cin >> surname;
- Queue<Human> tempp;
- for (Queue<Human>::Iterator i = tempQue.begin(); i != tempQue.end(); i++)
- {
- tempNode = search(i, tempQue.end(), surname, &compare4);
- if (tempNode)
- tempp.push(tempNode->node);
- }
- tempQue = tempp;
- tempp.clean();
- //break;
- }
- else if (i == 2)
- {
- cout << " Введите имя: ";
- string name;
- cin >> name;
- Queue<Human> tempp;
- for (Queue<Human>::Iterator i = tempQue.begin(); i != tempQue.end(); i++)
- {
- tempNode = search(i, humans.end(), name, &compare5);
- if (tempNode)
- tempp.push(tempNode->node);
- }
- tempQue = tempp;
- tempp.clean();
- //break;
- }
- else if (i == 3)
- {
- cout << " Введите год рождения: ";
- int year;
- cin >> year;
- Queue<Human> tempp;
- for (Queue<Human>::Iterator i = tempQue.begin(); i != tempQue.end(); i++)
- {
- tempNode = search(i, humans.end(), year, &compare6);
- if (tempNode)
- tempp.push(tempNode->node);
- }
- tempQue = tempp;
- tempp.clean();
- //break;
- }
- else if (i == 4)
- {
- if (!tempQue.getSize())
- {
- cout << "элементы отсутствуют" << endl;
- system("pause");
- break;
- }
- else
- {
- for (int i = 0; i < tempQue.getSize(); i++)
- {
- Human asd = tempQue[i];
- cout << asd << endl;
- }
- system("pause");
- break;
- }
- }
- else continue;
- } while (1);
- system("pause");
- break;
- }
- case '5':
- {
- system("cls");
- cout << " 1 - Фамилия" << endl;
- cout << " 2 - Имя" << endl;
- cout << " 3 - Год рождения" << endl;
- int i;
- cin >> i;
- if (i == 1)
- sort(humans.begin(), humans.end(), &compare1);
- if (i == 2)
- sort(humans.begin(), humans.end(), &compare2);
- if(i == 3)
- sort(humans.begin(), humans.end(), &compare3);
- else continue;
- break;
- }
- case '6' :
- {
- system("cls");
- Queue<int> a;
- for (int i = 0; i < 10; i++)
- a.push(i + 1);
- f.write(a);
- cout << "Информация записана в файл" << endl;
- system("pause");
- break;
- }
- case '0' :
- {
- return 0;
- }
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement