Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- // Вывести информацию для заданного пункта назначения в порядке возрастаняи времени вылета. Ключ: пункт назначения
- #include <iostream>
- #include <io.h>
- #include <conio.h>
- #include<cstdio>
- using namespace std;
- void Add();
- void Watching();
- void Searching();
- void Sorting();
- struct Stack
- {
- int info;
- Stack* next;
- };
- struct air
- {
- int number;
- char type[36];
- char area[36];
- double time;
- };
- int main()
- {
- setlocale(LC_ALL, "rus");
- int choice;
- while (true)
- {
- cout << "1. Добавление\n2. Просмотр\n3. Сортировка\n4. Поиск\n5. Выход" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:
- Add();
- cout << "Информация сохранена, нажмите любую кнопку" << endl;
- break;
- case 2:
- Watching();
- _getch();
- break;
- case 3:
- Sorting();
- break;
- case 4:
- //Searching();
- break;
- case 5:
- cout << "Программа завершена" << endl;
- return 0;
- break;
- default:
- cout<<"Повторите еще раз"<<endl;
- break;
- }
- system("cls");
- }
- }
- void Add()
- {
- FILE* f;
- air one;
- char filename[81];
- cout << "Введите имя файла" << endl;
- cin >>filename;
- f = fopen(filename, "a");
- if (f == NULL)
- {
- cout << "Данного файла не существует" << endl;
- return;
- }
- cout << "Введите номер рейса" << endl;
- cin >> one.number;
- cout << "Ведите тип самолета" << endl;
- cin >> one.type;
- cout << "Ведите пункт назначения" << endl;
- cin >> one.area;
- cout << "Ведите время вылета" << endl;
- cin >> one.time;
- fwrite(&one, sizeof(air), 1, f);
- fclose(f);
- }
- void Watching()
- {
- FILE* f;
- air one;
- char filename[81];
- cout << "Введите имя файла" << endl;
- cin >> filename;
- f = fopen(filename, "r");
- if (f == NULL)
- {
- cout << "Данного файла не существует" << endl;
- return;
- }
- while (fread(&one, sizeof(air), 1, f) == 1)
- {
- cout << "Номер рейса "<<one.number << endl;
- cout << "Тип самолета "<<one.type << endl;
- cout << "Пункт назначения "<<one.area << endl;
- cout << "Время вылета " << one.time;
- }
- fclose(f);
- return;
- }
- void Searching()
- {
- FILE* f;
- char filename[81];
- cout << "Введите имя файла" << endl;
- cin >> filename;
- f = fopen(filename, "r+");
- if (f == NULL)
- {
- cout << "Данного файла не существует" << endl;
- return;
- }
- fseek(f, 0, 0);
- int size = _filelength(_fileno(f));
- size /= sizeof(air);
- air* mas = new air[size];
- fread(mas, sizeof(air), size, f);
- int i, j, m, middle, choice;
- for (i = 0; i < size - 1; i++)
- {
- m = i;
- for (j = i + 1; j < size; j++)
- if (mas[i].time > mas[j].time) m = j;
- if (m != i)
- {
- air r = mas[m];
- mas[m] = mas[i];
- mas[i] = r;
- }
- }
- }
- void Sorting()
- {
- FILE* f;
- char filename[81];
- char place[81];
- int choice,cnt;
- cout << "Введите имя файла" << endl;
- cin >> filename;
- f = fopen(filename, "r+");
- if (f == NULL)
- {
- cout << "Такого файла не обнаружено!" << endl;
- return;
- }
- fseek(f, 0, 0);
- int size = _filelength(_fileno(f));
- size /= sizeof(air);
- air* a1=new air[size];
- air* mas = new air[size];//количество записей в файле
- cout << "Введите ключ" << endl;
- cin >> place[81];
- for (int g = 0; g < size-1; g++)
- {
- fread(mas, sizeof(air), size, f);
- if (strcmp(place, a1[g].area) == 0)
- {
- cnt++;
- }
- }
- air* arr = new air[cnt];
- for (int i = 0; i < size; i++)
- {
- }
- /*cin >> choice;
- cout << "1.QuickSort\n" << "2.Сортировка прямым выбором\n" << endl;
- switch (choice)
- {
- case 1:
- break;
- case 2:
- break;
- default:
- cout << "Неверный ввод" << endl;
- return;
- break;
- }*/
- fseek(f, 0, 0);
- fwrite(mas, sizeof(air), size, f);
- fclose(f);
- delete[]mas;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement