Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define fname "f.txt"
- int inputBase()
- {
- FILE *f;
- ship ship;
- int n, i = 0, k;
- char str[30];
- int c = 0;
- if ((f = fopen(fname, "wb")) == NULL)
- {
- printf("Не удалось создать или открыть файл\n");
- return -1;
- }
- getchar();
- A:printf("Введите количество кораблей, которые вы хотите добавить: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0') {
- goto B;
- }
- else
- {
- printf("Некорректный ввод:");
- goto A;
- }
- }
- B:n = atoi(str);
- for (i = 0; i < n; ++i)
- {
- printf("\nВведите данные о корабле № %d:\n", i + 1);
- C: printf("Введите название: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0')
- {
- goto D;
- }
- else
- {
- printf("Некорректный ввод:");
- goto C;
- }
- }
- D:strcpy(ship.name, str);
- E:printf("Введите год постройки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= '9' && str[i] >='0' || str[i] == '\0')
- {
- goto F;
- }
- else
- {
- printf("Некорректный ввод:");
- goto E;
- }
- }
- F:ship.year = atoi(str);
- G:printf("Введите страну постройки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0')
- {
- goto H;
- }
- else
- {
- printf("Некорректный ввод:");
- goto G;
- }
- }
- H:strcpy(ship.country, str);
- I:printf("Введите водоизмещение: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0')
- {
- goto J;
- }
- else
- {
- printf("Некорректный ввод:");
- goto I;
- }
- }
- J:ship.displacement = atoi(str);
- K:printf("Введите принадлежность к пароходству: 0/1");
- gets(str);
- while (str[i])
- {
- if (str[i] == '0' || str[i] = '1' || str[i] == '\0') {
- goto L;
- }
- else
- {
- printf("Некорректный ввод:");
- goto K;
- }
- }
- L:ship.company = atoi(str);
- M:printf("Введите тип корабля: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0') {
- goto N;
- }
- else
- {
- printf("Некорректный ввод:");
- goto M;
- }
- }
- N:strcpy(ship.type, str);
- Q:printf("Введите сумму страховки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0') {
- goto R;
- }
- else
- {
- printf("Некорректный ввод:");
- goto Q;
- }
- }
- R:ship.insurance = atoi(str);
- P:printf("Введите ФИО капитана: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0') {
- goto O;
- }
- else
- {
- printf("Некорректный ввод:");
- goto P;
- }
- }
- O:strcpy(ship.captain, str);
- fwrite(&ship, sizeof(ship), 1, f);
- }
- printf("\n");
- fclose(f);
- printf("База данных кораблей заполнена\n\n");
- return 0;
- }
- int addelement()
- {
- FILE *f;
- ship ship;
- char str[30];
- int k, i = 0;
- if ((f = fopen(fname, "rb+")) == NULL)
- {
- printf("Не удалось открыть файл\n");
- return 0;
- }
- gets();
- C1: printf("Введите название: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0')
- {
- goto D1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto C1;
- }
- }
- D1:strcpy(ship.name, str);
- E1:printf("Введите год постройки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= '9' && str[i] >='0' || str[i] == '\0')
- {
- goto F1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto E1;
- }
- }
- F1:ship.year = atoi(str);
- G1:printf("Введите страну постройки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0')
- {
- goto H1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto G1;
- }
- }
- H1:strcpy(ship.country, str);
- I1:printf("Введите водоизмещение: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0')
- {
- goto J1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto I1;
- }
- }
- J1:ship.displacement = atoi(str);
- K1:printf("Введите принадлежность к пароходству: 0/1");
- gets(str);
- while (str[i])
- {
- if (str[i] == '0' || str[i] = '1' || str[i] == '\0') {
- goto L1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto K1;
- }
- }
- L1:ship.company = atoi(str);
- M1:printf("Введите тип корабля: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0') {
- goto N1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto M1;
- }
- }
- N1:strcpy(ship.type, str);
- Q1:printf("Введите сумму страховки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0') {
- goto R1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto Q1;
- }
- }
- R1:ship.insurance = atoi(str);
- P1:printf("Введите ФИО капитана: ");
- gets(str);
- while (str[i])
- {
- if (str[i] <= 'z' && str[i] >= 'a' || str[i] == '\0') {
- goto O1;
- }
- else
- {
- printf("Некорректный ввод:");
- goto P1;
- }
- }
- O1:strcpy(ship.captain, str);
- fseek(f, 0, SEEK_END);
- fwrite(&ship, sizeof(ship), 1, f);
- fclose(f);
- printf("\nДанный корабль\n\n");
- return 0;
- }
- int delelement()
- {
- FILE *f;
- ship ship;
- int i, ind, size;
- if ((f = fopen(fname, "rb+")) == NULL)
- {
- printf("Не удалось открыть файл\n");
- return 0;
- }
- printf("Введите номер корабля, который вы хотите удалить: ");
- scanf("%d", &ind);
- fseek(f, 0, SEEK_END);
- size = ftell(f) / sizeof(ship);
- while ((ind > size) || (ind < 1))
- {
- printf("\nВ базе нет корабля с таким номером, введите новый номер : ");
- scanf("%d", &ind);
- }
- ind--;
- for (i = ind; i < size - 1; i++)
- {
- fseek(f, (i + 1) * sizeof(ship), SEEK_SET);
- fread(&ship, sizeof(ship), 1, f);
- fseek(f, (i) * sizeof(ship), SEEK_SET);
- fwrite(&ship, sizeof(ship), 1, f);
- }
- chsize(_fileno(f), (size - 1) * sizeof(ship));
- fclose(f);
- printf("\nКорабль с номером %d успешно удален\n\n", ind+1);
- return 0;
- }
- int search()
- {
- FILE *f;
- ship ship;
- char str[30];
- int i=0, ind,n;
- int k = 0;
- if ((f = fopen(fname, "rb")) == NULL)
- {
- printf("Не удалось открыть файл\n");
- return 0;
- }
- printf("Выберите поле:\n1 - Название\n2 - Год постройки\n3 - Страна постройки\n4 - Водоизмещение\n5 - Принадлежность к пароходству\n6 - Тип корабля\n7 - Сумма страховки\n8 - ФИО капитана\n\n\n");
- scanf("%d", &ind);
- printf("\n");
- gets(str);
- switch (ind)
- {
- case 1:
- printf("Введите название корабля: ");
- gets(str);
- printf("\nНайденные корабли с заданным названием:\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (!strcmp(ship.name, str))
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- case 2:
- A2:printf("Введите год постройки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] < '9' && str[i] > '0' || str[i] == '\0') {
- goto A2;
- }
- else
- {
- printf("Некорректный ввод:");
- goto B2;
- }
- }
- B2:n = atoi(str);
- printf("\nНайденные корабли :\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (ship.name==n)
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- case 3:
- printf("Введите страну постройки: ");
- gets(str);
- printf("\nНайденные корабли:\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (!strcmp(ship.otch, str))
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- case 4:
- C2:printf("Введите водоизмещение: ");
- gets(str);
- while (str[i])
- {
- if (str[i] < '9' && str[i] > '0' || str[i] == '\0') {
- goto C2;
- }
- else
- {
- printf("Некорректный ввод:");
- goto D2;
- }
- }
- D2:n = atoi(str);
- printf("\nНайденные корабли:\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (ship.street==n)
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- case 5:
- E2:printf("Введите принадлежность к пароходству: ");
- gets(str);
- while (str[i])
- {
- if (str[i] < '9' && str[i] > '0' || str[i] == '\0') {
- goto E2;
- }
- else
- {
- printf("Некорректный ввод:");
- goto F2;
- }
- }
- F2:n = atoi(str);
- printf("\nНайденные корабли:\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (ship.numhouse==n)
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- case 6:
- G2:printf("Введите тип корабля: ");
- gets(str);
- while (str[i])
- {
- if (str[i] < '9' && str[i] > '0' || str[i] == '\0') {
- goto G2;
- }
- else
- {
- printf("Некорректный ввод:");
- goto H2;
- }
- }
- H2:n = atoi(str);
- printf("\nНайденные корабли:\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (ship.numflat == n)
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- case 7:
- I2:printf("Введите сумму страховки: ");
- gets(str);
- while (str[i])
- {
- if (str[i] < '9' && str[i] > '0' || str[i] == '\0') {
- goto I2;
- }
- else
- {
- printf("Некорректный ввод:");
- goto J2;
- }
- }
- J2:n = atoi(str);
- printf("\nНайденные корабли:\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (ship.year == n)
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- case 8:
- K2:printf("Введите ФИО капитана: ");
- gets(str);
- while (str[i])
- {
- if (str[i] < '9' && str[i] > '0' || str[i] == '\0') {
- goto K2;
- }
- else
- {
- printf("Некорректный ввод:");
- goto L2;
- }
- }
- L2:n = atoi(str);
- printf("\nНайденные корабли:\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- {
- if (ship.numotd== n)
- printf("|%-15s|%-15d|%-15s|%-15d|%-15d|%-15s|%-15d|%-15s|\n", ship.name, ship.year, ship.country, ship.displacement, ship.company, ship.type, ship.insurance, ship.captain);
- }
- }
- printf("\n");
- break;
- default:
- printf("Некорректный ввод\n\n");
- }
- fclose(f);
- return 0;
- }
- int edit()
- {
- FILE *f;
- ship ship;
- char str[30];
- int i, ind, size, n;
- int k = 0;
- if ((f = fopen(fname, "rb+")) == NULL)
- {
- printf("Не удалось открыть файл\n");
- return -1;
- }
- sad:
- printf("Введите номер сотрудника: ");
- scanf("%s", str);
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0')
- {
- continue;
- }
- else
- {
- goto sad;
- }
- }
- ind = atoi(str);
- fseek(f, 0, SEEK_END);
- size = ftell(f) / sizeof(ship);
- while ((ind > size) || (ind < 1))
- {
- printf("\nВ базе нет сотрудника с таким номером, введите новый номер сотрудника: ");
- scanf("%d", &ind);
- }
- ind--;
- fseek(f, ind * sizeof(ship), SEEK_SET);
- fread(&ship, sizeof(ship), 1, f);
- fseek(f, ftell(f) - sizeof(ship), SEEK_SET);
- printf("Выберите поле:\n1 - Фамилия\n2 - Имя\n3 - Отчество\n4 - Улица\n5 - Номер дома\n6 - Номер квартиры\n7 - Год рождения\n8 - Номер отдела\n9 - Должность\n10 - Оклад\n11 - Телефон\n\n");
- scanf("%d", &i);
- printf("\n");
- gets(str);
- switch (i)
- {
- case 1:
- printf("Введите новую фамилию: ");
- gets(ship.surname);
- printf("\n");
- break;
- case 2:
- printf("Введите новое имя: ");
- gets(ship.name);
- printf("\n");
- break;
- case 3:
- printf("Введите новое отчество: ");
- gets(ship.otch);
- printf("\n");
- break;
- case 4:
- printf("Введите новую улицу: ");
- gets(ship.street);
- printf("\n");
- break;
- case 5:
- A2:printf("Введите новый номер дома: ");
- scanf("%s", str);
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0')
- {
- continue;
- }
- else
- {
- printf("Некорректный ввод:");
- goto A2;
- }
- }
- n = atoi(str);
- ship.numhouse = n;
- printf("\n");
- break;
- case 6:
- printf("Введите новый номер квартиры: ");
- C:gets(str);
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0') {
- goto D;
- }
- else
- {
- printf("Некорректный ввод:");
- goto C;
- }
- }
- D:n = atoi(str);
- ship.numflat = n;
- printf("\n");
- break;
- case 7:
- printf("Введите год рождения: ");
- E:gets(str);
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0') {
- goto F;
- }
- else
- {
- printf("Некорректный ввод:");
- goto E;
- }
- }
- F:n = atoi(str);
- ship.year = n;
- printf("\n");
- break;
- case 8:
- printf("Введите новый номер отдела: ");
- G:gets(str);
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0') {
- goto H;
- }
- else
- {
- printf("Некорректный ввод:");
- goto G;
- }
- }
- H:n = atoi(str);
- ship.numotd = n;
- printf("\n");
- break;
- case 9:
- printf("Введите новую должность: ");
- gets(ship.dolzhn);
- printf("\n");
- break;
- case 10:
- printf("Введите новый оклад: ");
- I:gets(str);
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] <= '9' && str[i] >= '0' || str[i] == '\0') {
- goto J;
- }
- else
- {
- printf("Некорректный ввод:");
- goto I;
- }
- }
- J:n = atoi(str);
- ship.oklad = n;
- printf("\n");
- break;
- case 11:
- printf("Введите новый номер телефона: ");
- K:gets(str);
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] <= '9' && str[i] >='0' || str[i] == '\0') {
- goto L;
- }
- else
- {
- printf("Некорректный ввод:");
- goto K;
- }
- }
- L:n = atoi(str);
- ship.phone = n;
- printf("\n");
- break;
- default:
- printf("Некорректный ввод\n\n");
- }
- fwrite(&ship, sizeof(ship), 1, f);
- fclose(f);
- return 0;
- }
- int sort()
- {
- FILE *f;
- ship tmp;
- ship *sotr = NULL;
- int i, j, ind1, ind2, size;
- if ((f = fopen(fname, "rb+")) == NULL)
- {
- printf("Не удалось открыть файл\n");
- return 0;
- }
- fseek(f, 0, SEEK_END);
- size = ftell(f) / sizeof(ship);
- fseek(f, 0, SEEK_SET);
- sotr = (ship*)malloc(size * sizeof(ship));
- for (i = 0; i < size; ++i)
- {
- fread(&sotr[i], sizeof(ship), 1, f);
- }
- printf("Выберите поле:\n1 - Фамилия\n2 - Имя\n3 - Отчество\n4 - Улица\n5 - Номер дома\n6 - Номер квартиры\n7 - Год рождения\n8 - Номер отдела\n9 - Должность\n10 - Оклад\n11 - Телефон\n\n");
- scanf("%d", &ind1);
- printf("\n");
- switch (ind1)
- {
- case 1:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].surname, sotr[j + 1].surname) > 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- break;
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].surname, sotr[j + 1].surname) < 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- break;
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 2:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].name, sotr[j + 1].name) > 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- break;
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].name, sotr[j + 1].name) < 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- break;
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 3:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].otch, sotr[j + 1].otch) > 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- break;
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].otch, sotr[j + 1].otch) < 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- break;
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 4:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].street, sotr[j + 1].street) > 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].street, sotr[j + 1].street) < 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 5:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].numhouse>sotr[j + 1].numhouse)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].numhouse < sotr[j + 1].numhouse)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 6:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].numflat > sotr[j + 1].numflat)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].numflat < sotr[j + 1].numflat)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 7:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].year > sotr[j + 1].year)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].year < sotr[j + 1].year)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 8:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].numotd > sotr[j + 1].numotd)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].numotd < sotr[j + 1].numotd)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 9:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].dolzhn, sotr[j + 1].dolzhn) > 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (strcmp(sotr[j].dolzhn, sotr[j + 1].dolzhn) < 0)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 10:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].oklad > sotr[j + 1].oklad)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].oklad < sotr[j + 1].oklad)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- case 11:
- printf("1 - по возрастанию\n2 - по убыванию\n\n");
- scanf("%d", &ind2);
- printf("\n");
- switch (ind2)
- {
- case 1:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].phone > sotr[j + 1].phone)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- case 2:
- for (i = size - 1; i >= 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (sotr[j].phone < sotr[j + 1].phone)
- {
- tmp = sotr[j];
- sotr[j] = sotr[j + 1];
- sotr[j + 1] = tmp;
- }
- }
- }
- default:
- printf("Некорректный ввод\n\n");
- }
- break;
- default:
- printf("Некорректный ввод\n\n");
- }
- fseek(f, 0, SEEK_SET);
- for (i = 0; i < size; ++i)
- {
- fwrite(&sotr[i], sizeof(ship), 1, f);
- }
- free(sotr);
- sotr= NULL;
- fclose(f);
- free(sotr);
- return 0;
- }
- int outputBase()
- {
- FILE *f;
- ship ship;
- if ((f = fopen(fname, "rb")) == NULL)
- {
- printf("Не удалось открыть файл\n");
- return 0;
- }
- printf("База данных:\n");
- printf("| Фамилия | Имя | Отчество | Улица |Номер дома |Номер квартиры|Год рождения|Номер отдела| Должность | Оклад | Телефон |\n");
- while (!feof(f))
- {
- fread(&ship, sizeof(ship), 1, f);
- if (!feof(f))
- printf("|%-15s|%-15s|%-15s|%-15s|%-11d|%-14d|%-12d|%-12d|%-15s|%-11d|%-13d|\n", ship.surname, ship.name, ship.otch, ship.street, ship.numhouse, ship.numflat, ship.year, ship.numotd, ship.dolzhn, ship.oklad, ship.phone);
- }
- printf("\n");
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement