Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #include <Windows.h>
- #include <clocale>
- #include <cstdlib>
- #include <iterator>
- #include <algorithm>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- struct FIO {
- char name[20];
- char surname[20];
- char patronymic[20];
- };
- struct Student {
- FIO fio;
- int group;
- int exams;
- int mark[7];
- char disp[7][20];
- };
- struct stud {
- Student uch;
- stud* next;
- stud* prev;
- }*hbeg, *hend, *w, *h;
- void read_file(stud** hbeg, stud** hend) {
- ifstream fail;
- fail.open("students_info.txt", ios::in);
- int i = 0;
- while (fail) {
- w = new stud;
- fail >> w->uch.fio.surname;
- if (strlen(w->uch.fio.surname) < 2) {
- delete w;
- break;
- }
- fail >> w->uch.exams;
- for (int j = 0; j < w->uch.exams; j++) {
- fail >> w->uch.disp[j];
- }
- for (int j = w->uch.exams; j < 7; j++) {
- strcpy_s(w->uch.disp[j]," ");
- }
- fail >> w->uch.fio.name;
- fail >> w->uch.fio.patronymic;
- fail >> w->uch.group;
- for (int j = 0; j < w->uch.exams; j++) {
- fail >> w->uch.mark[j];
- }
- if (i == 0) {
- w->next = 0;
- w->prev = 0;
- *hbeg = *hend = w;
- i++;
- }
- else {
- w->prev = *hend;
- w->next = 0;
- (*hend)->next = w;
- *hend = w;
- }
- }
- fail.close();
- }
- void print_info(stud* hbeg) {
- w = hbeg;
- while (w != 0) {
- cout << setw(25) << left << w->uch.fio.surname << " " << setw(4) << left << w->uch.exams;
- for (int j = 0; j < w->uch.exams; j++) {
- cout << w->uch.disp[j] << " ";
- }
- cout << endl;
- cout << setw(10) << left << w->uch.fio.name << " " << setw(15) << left << w->uch.fio.patronymic << setw(4) << left << w->uch.group << " ";
- for (int j = 0; j < w->uch.exams; j++) {
- cout << setw(4) << w->uch.mark[j] << " ";
- }
- cout << endl << endl;
- w = w->next;
- }
- }
- void add_info(stud** hend) {
- w = new stud;
- w->next = 0;
- cout << "Введите ФИО студента: ";
- cin >> w->uch.fio.surname;
- cin >> w->uch.fio.name;
- cin >> w->uch.fio.patronymic;
- cout << "Введите число экзаменов: ";
- cin >> w->uch.exams;
- cout << "Введите номер группы: ";
- cin >> w->uch.group;
- cout << "Введите названия экзаменов: ";
- for (int j = 0; j < w->uch.exams; j++) {
- cin >> w->uch.disp[j];
- }
- for (int j = w->uch.exams; j < 7; j++) {
- strcpy_s(w->uch.disp[j], " ");
- }
- cout << "Введите оценки студента по этим предметам: ";
- for (int j = 0; j < w->uch.exams; j++) {
- cin >> w->uch.mark[j];
- }
- w->prev = *hend;
- (*hend)->next = w;
- *hend = w;
- cout << endl;
- }
- void search_info(stud* hbeg) {
- w = hbeg;
- int ttt = 0;
- char key[20];
- cout<<"Введите слово для поиска: ";
- cin >> key;
- while (w != 0) {
- if (ttt == 0) {
- if (strcmp(key, w->uch.fio.name) == 0 || strcmp(key, w->uch.fio.surname) == 0 || strcmp(key, w->uch.fio.patronymic) == 0) {
- cout << setw(25) << left << w->uch.fio.surname << " " << setw(4) << left << w->uch.exams;
- for (int j = 0; j < w->uch.exams; j++) {
- cout << w->uch.disp[j] << " ";
- }
- cout << endl;
- cout << setw(10) << left << w->uch.fio.name << " " << setw(15) << left << w->uch.fio.patronymic << setw(4) << left << w->uch.group << " ";
- for (int j = 0; j < w->uch.exams; j++) {
- cout << setw(4) << w->uch.mark[j] << " ";
- }
- cout << endl << endl;
- }
- ttt++;
- }
- w = w->next;
- }
- if (ttt == 0) {
- printf_s("Не найдено!\n");
- }
- }
- void delete_info(stud** hbeg, stud **hend) {
- cout << "Введите ключ,по которому хотите удалить: ";
- char key[20];
- cin >> key;
- w = *hbeg;
- while (w != 0) {
- if (strcmp(key, w->uch.fio.name) == 0 || strcmp(key, w->uch.fio.surname) == 0 || strcmp(key, w->uch.fio.patronymic) == 0) {
- if (w == *hbeg) {
- *hbeg = w->next;
- (*hbeg)->prev = 0;
- }
- else if (w == *hend) {
- *hend = w->prev;
- (*hend)->next = 0;
- }
- else {
- (w->prev)->next = w->next;
- (w->next)->prev = w->prev;
- }
- }
- w = w->next;
- }
- }
- void sort(stud* hbeg, stud* hend) {
- char help[20];
- int k;
- for (stud*h = hbeg; h != hend; h = h->next) {
- for (stud*w = h; w != hend; w = w->next) {
- if (strcmp(w->uch.fio.surname, (w->next)->uch.fio.surname) > 0) {
- strcpy_s(help, (w->next)->uch.fio.surname);
- strcpy_s((w->next)->uch.fio.surname, w->uch.fio.surname);
- strcpy_s(w->uch.fio.surname, help);
- strcpy_s(help, (w->next)->uch.fio.name);
- strcpy_s((w->next)->uch.fio.name, w->uch.fio.name);
- strcpy_s(w->uch.fio.name, help);
- strcpy_s(help, (w->next)->uch.fio.patronymic);
- strcpy_s((w->next)->uch.fio.patronymic, w->uch.fio.patronymic);
- strcpy_s(w->uch.fio.patronymic, help);
- k = (w->next)->uch.exams;
- (w->next)->uch.exams = w->uch.exams;
- w->uch.exams = k;
- k = (w->next)->uch.group;
- (w->next)->uch.group = w->uch.group;
- w->uch.group = k;
- for (int i = 0; i < w->uch.exams; i++) {
- k = (w->next)->uch.mark[i];
- (w->next)->uch.mark[i] = w->uch.mark[i];
- w->uch.mark[i] = k;
- }
- for (int i = 0; i < 7; i++) {
- strcpy_s(help, (w->next)->uch.disp[i]);
- strcpy_s((w->next)->uch.disp[i], w->uch.disp[i]);
- strcpy_s(w->uch.disp[i], help);
- }
- }
- }
- }
- }
- void sort1(stud* hbeg, stud* hend) {
- char help[20];
- int k;
- for (stud*h = hbeg; h != hend; h = h->next) {
- for (stud* w = h; w != hend; w = w->next) {
- if (strcmp(w->uch.fio.surname, (w->next)->uch.fio.surname) > 0 || strcmp(w->uch.fio.surname, (w->next)->uch.fio.surname) == 0 && strcmp(w->uch.fio.name, (w->next)->uch.fio.name) > 0) {
- strcpy_s(help, (w->next)->uch.fio.name);
- strcpy_s((w->next)->uch.fio.name, w->uch.fio.name);
- strcpy_s(w->uch.fio.name, help);
- strcpy_s(help, (w->next)->uch.fio.surname);
- strcpy_s((w->next)->uch.fio.surname, w->uch.fio.surname);
- strcpy_s(w->uch.fio.surname, help);
- strcpy_s(help, (w->next)->uch.fio.patronymic);
- strcpy_s((w->next)->uch.fio.patronymic, w->uch.fio.patronymic);
- strcpy_s(w->uch.fio.patronymic, help);
- k = (w->next)->uch.exams;
- (w->next)->uch.exams = w->uch.exams;
- w->uch.exams = k;
- k = (w->next)->uch.group;
- (w->next)->uch.group = w->uch.group;
- w->uch.group = k;
- for (int i = 0; i < w->uch.exams; i++) {
- k = (w->next)->uch.mark[i];
- (w->next)->uch.mark[i] = w->uch.mark[i];
- w->uch.mark[i] = k;
- }
- for (int j = 0; j < 7; j++) {
- strcpy_s(help, (w->next)->uch.disp[j]);
- strcpy_s((w->next)->uch.disp[j], w->uch.disp[j]);
- strcpy_s(w->uch.disp[j], help);
- }
- }
- }
- }
- }
- void add_info1(stud** hbeg, stud** hend) {
- int k;
- cout<<"Введите номер ячейки, перед которой хотите вставить данные: ";
- cin >> k;
- w = new stud;
- h = *hbeg;
- cout << "Введите ФИО студента: ";
- cin >> w->uch.fio.surname;
- cin >> w->uch.fio.name;
- cin >> w->uch.fio.patronymic;
- cout << "Введите число экзаменов: ";
- cin >> w->uch.exams;
- cout << "Введите номер группы: ";
- cin >> w->uch.group;
- cout << "Введите названия экзаменов: ";
- for (int j = 0; j < w->uch.exams; j++) {
- cin >> w->uch.disp[j];
- }
- for (int j = w->uch.exams; j < 7; j++) {
- strcpy_s(w->uch.disp[j], " ");
- }
- cout << "Введите оценки студента по этим предметам: ";
- for (int j = 0; j < w->uch.exams; j++) {
- cin >> w->uch.mark[j];
- }
- for (int i = 0; h != 0; i++, h = h->next) {
- if ((i == k) && h == *hbeg) {
- (*hbeg)->prev = w;
- w->next = *hbeg;
- *hbeg = w;
- (*hbeg)->prev = 0;
- }
- else if (i == k) {
- (h->prev)->next = w;
- w->prev = h->prev;
- h->prev = w;
- w->next = h;
- }
- }
- }
- void add_info2(stud** hbeg, stud** hend) {
- int k;
- cout<<"Введите номер ячейки, после которой хотите вставить данные: ";
- cin >> k;
- w = new stud;
- h = *hbeg;
- cout << "Введите ФИО студента: ";
- cin >> w->uch.fio.surname;
- cin >> w->uch.fio.name;
- cin >> w->uch.fio.patronymic;
- cout << "Введите число экзаменов: ";
- cin >> w->uch.exams;
- cout << "Введите номер группы: ";
- cin >> w->uch.group;
- cout << "Введите названия экзаменов: ";
- for (int j = 0; j < w->uch.exams; j++) {
- cin >> w->uch.disp[j];
- }
- for (int j = w->uch.exams; j < 7; j++) {
- strcpy_s(w->uch.disp[j], " ");
- }
- cout << "Введите оценки студента по этим предметам: ";
- for (int j = 0; j < w->uch.exams; j++) {
- cin >> w->uch.mark[j];
- }
- for (int i = 0; h != 0; i++, h = h->next) {
- if ((i == k) && h == *hend) {
- (*hend)->next = w;
- w->prev = *hend;
- w->next = 0;
- *hend = w;
- }
- else if (i == k) {
- (h->next)->prev = w;
- w->next = h->next;
- h->next = w;
- w->prev = h;
- }
- }
- }
- int main() {
- setlocale(LC_ALL, "rus");
- ifstream fail;
- fail.open("students_info.txt", ios::in);
- int k = -1;
- while (k != 10) {
- printf(" 1-формирование данных\n 2-добавить данные\n 3-поиск данных по ключу\n 4-удаление данных по ключу\n 5-вставка данных в массив перед i-ой записью\n 6-вставка данных в массив после i-ой записи\n 7-сортировка по фамилии\n 8-сортировка по имени и фамилии\n 9-сохранение данных в файл\n 0-вывод данных\n 10-выход\n");
- cin >> k;
- if (k == 1)
- read_file(&hbeg, &hend);
- if (k == 2) {
- add_info(&hend);
- }
- if (k == 3)
- search_info(hbeg);
- if (k == 4) {
- delete_info(&hbeg, &hend);
- }
- if (k == 5) {
- add_info1(&hbeg, &hend);
- }
- if (k == 6) {
- add_info2(&hbeg, &hend);
- }
- if (k == 7) {
- sort(hbeg, hend);
- }
- if (k == 8) {
- sort1(hbeg, hend);
- }
- if (k == 9) {
- w = hbeg;
- ofstream fail;
- fail.open("students_info2.txt", ios::out);
- for (; w != 0; w = w->next) {
- fail << setw(25) << left << w->uch.fio.surname << " " << setw(4) << left << w->uch.exams;
- for (int j = 0; j < w->uch.exams; j++) {
- fail << w->uch.disp[j] << " ";
- }
- fail << endl;
- fail << setw(10) << left << w->uch.fio.name << " " << setw(15) << left << w->uch.fio.patronymic << setw(4) << left << w->uch.group << " ";
- for (int j = 0; j <w->uch.exams; j++) {
- fail << setw(4) << w->uch.mark[j] << " ";
- }
- fail << endl;
- }
- fail.close();
- }
- if (k == 0)
- print_info(hbeg);
- if (k == 10) {
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement