Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <stdlib.h>
- #include <iomanip>
- #include <conio.h>
- #include <iostream>
- #include <locale.h>
- #include <windows.h>
- #include <io.h>
- #include <fcntl.h>
- #include <string>
- using namespace std;
- const string items[10] = {
- "Создать список или добавить новый эл-т",
- " Удаление элементов списка ",
- " Просмотр списка ",
- " Запись данных в файл ",
- " Чтение из файла ",
- " Изменить ",
- " Поиск ",
- " Сортировка ",
- " Выполнение ",
- " Выход "
- }
- ;
- const string items2[10] =
- {
- "Сортировка по пропуску занятий(меньше) ",
- "Сортировка по пропуску занятий(больше)",
- "Выход"
- };
- const string items8[10] =
- {
- "Сортировка по пропуску лекций(меньше) ",
- "Сортировка по пропуску лекций(больше)",
- "Выход"
- };
- const string items9[10] =
- {
- "Сортировка по пропуску лекций ",
- "Сортировка по пропуску занятий",
- "Выход"
- };
- const string items3[10] =
- {
- "Поиск по шифру группы",
- "Поиск среднего балла группы",
- "Выход"
- };
- const string items4[10] =
- {
- "Входня таблица",
- "Выход"
- };
- const string items5[10] =
- {
- "Изменить шифр группы",
- "Изменить шифр дисципилны",
- "Выход"
- };
- const string items6[10] =
- {
- "Чтение файла ",
- "Чтение бинарного файла",
- "Выход"
- };
- const string items7[10] =
- {
- "Запись файла ",
- "Запись бинарного файла",
- "Выход"
- };
- const int
- up = 72,
- down = 80,
- right_btn = 77,
- left_btn = 75,
- enter = 13,
- esc = 27,
- del = 83,
- dl = 20;
- //-------------------------------------------
- int height = 0, width = 0;
- int koli = 1;
- //-------------------------------------------
- //-------------------------------------------
- struct tabl
- {
- string shg;
- string shd, ot, xoro, yd, noyd, prl, prz;
- float srb = 0;
- };
- struct tabli
- {
- tabl t;
- tabli* next = 0;
- tabli* pred = 0;
- };
- //-------------------------------------------
- tabli* dob(tabli* end, const tabli& z);
- tabli* dob_first(const tabli& z);
- tabli* udal(tabli* beg);
- void output(tabli* beg);
- //tabli* delete_el(tabli* beg);
- tabli vvod_tabli();
- void prosmotr_vh(tabli* beg);
- void prosmotr_vih(tabli* beg);
- void SetColor(int text, int bg);
- void poiskshd(tabli* beg);
- int read_file(string filename, tabli** beg, tabli** end);
- int write_file(string filename, tabli* temp);
- int read_bin_file(string filename, tabli** beg, tabli** end);
- int write_file_binary(string filename, tabli* beg);
- void cls();
- int changeshg(tabli* beg, string& user_shg, string& new_user_shg);
- int changeshd(tabli* beg, string& user_shd, string& new_user_shd);
- void poiskshg(tabli* beg);
- void sortirovka_prz(tabli** beg);
- void sortirovka_prz1(tabli** beg);
- void sortirovka_prl(tabli** beg);
- void sortirovka_prl1(tabli** beg);
- void print_vih(const tabli& z);
- void print_vh(const tabli& z);
- void gotoxy(int xpos, int ypos);
- int menu(int& active, const string items[], int num_el);
- int menu2(int& active, const string items[], int num_el);
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- int main()
- {
- // меняем размер шрифта
- CONSOLE_FONT_INFOEX cfi;
- cfi.cbSize = sizeof(cfi);
- cfi.nFont = 0;
- cfi.dwFontSize.X = 0;
- cfi.dwFontSize.Y = 19; //шрифт
- cfi.FontFamily = FF_DONTCARE;
- cfi.FontWeight = FW_NORMAL;
- SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- HANDLE hCon;
- // ширина и высоат
- hCon = GetStdHandle(-12);
- CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
- if (GetConsoleScreenBufferInfo(hCon, &consoleInfo))
- {
- width = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1;
- height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
- }
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- system("cls");
- ShowWindow(GetConsoleWindow(), SW_MAXIMIZE); // полноэкранный режим
- setlocale(LC_ALL, "Rus");
- system("color 2B");
- tabli* beg = NULL,
- * end = NULL, input;
- string filename;
- int n = 0;
- int current = 1;
- string user_shg, new_user_shg;
- string user_shd, new_user_shd;
- while (1)
- {
- system("cls");
- switch (menu(current, items, 10))
- {
- case 1://создание списка или добовление нового эл-та в список
- system("cls");
- if (beg)
- end = dob(end, vvod_tabli());
- else
- {
- beg = dob_first(vvod_tabli());
- end = beg;
- }
- koli++;
- break;
- case 2:
- system("cls");//удаление всех элементов в списке
- //beg = delete_el(beg);
- cout << "Нажмите любую клавишу" << endl;
- cin.get();
- break;
- case 3:
- //просмотр
- current = 1;
- switch (menu2(current, items4, 2))
- {
- case 1:
- system("cls");
- //prosmotr_vh(beg);
- output(beg);
- break;
- case 2:
- system("cls");
- break;
- }
- break;
- case 4://запись
- current = 1;
- switch (menu2(current, items7, 3))
- {
- case 1:
- system("cls");
- write_file(filename, beg);
- break;
- case 2:
- system("cls");
- write_file_binary(filename, beg);
- break;
- case 3:
- system("cls");
- break;
- }
- break;
- case 5://чтение
- current = 1;
- switch (menu2(current, items6, 3))
- {
- case 1:
- system("cls");
- //чтение из файла
- read_file(filename, &beg, &end);
- break;
- case 2:
- system("cls");
- read_bin_file(filename, &beg, &end);
- break;
- case 3:
- break;
- }
- break;
- case 6://изменение
- system("cls");
- {
- int Num, current = 1;
- switch (menu2(current, items5, 3))
- {
- case 1:
- system("cls");
- cout << "Введите шифр группы, которую вы хотите изменить: " << endl;
- cin >> user_shg;
- cout << "Введите новый шифр: " << endl;
- cin >> new_user_shg;
- Num = changeshg(beg, user_shg, new_user_shg);
- if (Num == 1) cout << "шифр перезаписан." << endl;
- else cout << "шифр не найден!" << endl;
- system("pause");
- changeshg(beg, user_shg, new_user_shg);
- cin.get();
- break;
- case 2:
- system("cls");
- cout << "Введите шифр дисциплины, которую вы хотите изменить: " << endl;
- cin >> user_shd;
- cout << "Введите новый шифр: " << endl;
- cin >> new_user_shd;
- Num = changeshd(beg, user_shd, new_user_shd);
- if (Num == 1) cout << "шифр перезаписан." << endl;
- else cout << "шифр не найден!" << endl;
- system("pause");
- changeshd(beg, user_shd, new_user_shd);
- cin.get();
- break;
- case 3:
- system("cls");
- break;
- }
- break;
- }
- case 7:
- system("cls");
- //поиск
- {
- int current = 1;
- switch (menu2(current, items3, 3))
- {
- case 1:
- system("cls");
- poiskshg(beg);
- cin.get();
- break;
- case 2:
- system("cls");
- poiskshd(beg);
- cin.get();
- break;
- case 3:
- break;
- }
- break;
- }
- case 8://ростировка
- system("cls");
- {
- int current = 1;
- switch (menu2(current, items9, 3))
- {
- case 1:
- {
- system("cls");
- switch (menu2(current, items8, 3))
- {
- case 1:
- system("cls");
- sortirovka_prl(&beg);
- prosmotr_vh(beg);
- cin.get();
- break;
- case 2:
- system("cls");
- sortirovka_prl1(&beg);
- prosmotr_vh(beg);
- cin.get();
- break;
- case 3:
- break;
- }
- break;
- }
- case 2:
- {
- system("cls");
- switch (menu2(current, items2, 3))
- {
- case 1:
- system("cls");
- sortirovka_prz(&beg);
- prosmotr_vh(beg);
- cin.get();
- break;
- case 2:
- system("cls");
- sortirovka_prz1(&beg);
- prosmotr_vh(beg);
- cin.get();
- break;
- case 3:
- break;
- }
- break;
- }
- case 3:
- break;
- }
- break;
- }
- case 9://выполнение
- system("cls");
- {
- prosmotr_vih(beg);
- break;
- }
- case 10://выход
- system("cls");
- return 0;
- }
- }
- int saved = 0;
- return 0;
- }
- //-----------------------------------------------------------------------------
- tabli* dob(tabli* end, const tabli& z)
- {
- tabli* newE = new tabli;
- *newE = z;
- newE->next = 0;
- end->next = newE;
- end = newE;
- return end;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- tabli* dob_first(const tabli& z)
- {
- tabli* beg = new tabli;
- *beg = z;
- beg->next = 0;
- return beg;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- tabli* udal(tabli* beg)
- {
- tabli* temp;
- if (!beg)
- {
- cout << "список пустой" << endl;
- cin.get();
- return 0;
- }
- while (beg)
- {
- temp = beg;
- beg = beg->next;
- delete temp;
- }
- cout << "удаление прошло успешно" << endl;
- return beg;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- tabli vvod_tabli()
- {
- tabli z;
- cout << "Введите шифр группы:" << endl;
- while (1)
- {
- cin >> z.t.shg;
- if ((z.t.shg).length() == 6)
- break;
- cout << "Ошибка ввода!" << endl;
- }
- cout << "Введите шифр дисциплины:" << endl;
- while (1)
- {
- cin >> z.t.shd;
- if ((z.t.shd).length() == 6)
- break;
- cout << "Ошибка ввода!" << endl;
- }
- cout << "Введите количество оценок отлично:" << endl;
- while (1)
- {
- cin >> z.t.ot;
- if (!cin) {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- }
- else if (stoi((z.t.ot)) >= 0)
- break;
- cout << "Ошибка ввода, введена буква !" << endl;
- }
- cout << "Введите количество оценок хорошо:" << endl;
- while (1)
- {
- cin >> z.t.xoro;
- if (!cin) {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- }
- else if (stoi((z.t.xoro)) >= 0)
- break;
- cout << "Ошибка ввода, введена буква !" << endl;
- }
- cout << "Введите количество оценок удовлетворительно:" << endl;
- while (1)
- {
- cin >> z.t.yd;
- if (!cin) {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- }
- else if (stoi((z.t.yd)) >= 0)
- break;
- cout << "Ошибка ввода, введена буква !!" << endl;
- }
- cout << "Введите количество оценок неудовлетворительно:" << endl;
- while (1)
- {
- cin >> z.t.noyd;
- if (!cin) {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- }
- else if (stoi((z.t.noyd)) >= 0)
- break;
- cout << "Ошибка ввода, введена буква !!" << endl;
- }
- cout << "Введите количество пропущеныйх лекций:" << endl;
- while (1)
- {
- cin >> z.t.prl;
- if (!cin) {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- }
- else if (stoi((z.t.prl)) >= 0)
- break;
- cout << "Ошибка ввода, введена буква !!" << endl;
- }
- cout << "Введите количество пропущеныйх практических заданй:" << endl;
- while (1)
- {
- cin >> z.t.prz;
- if (!cin) {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- }
- else if (stoi((z.t.prz)) >= 0)
- break;
- cout << "Ошибка ввода, введена буква !" << endl;
- }
- z.t.srb = (((5 * stoi(z.t.ot)) + (4 * stoi(z.t.xoro)) + (3 * stoi(z.t.yd)) + (2 * stoi(z.t.noyd))) / (stoi(z.t.ot) + stoi(z.t.xoro) + stoi(z.t.yd) + stoi(z.t.noyd)));
- koli++;
- return z;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void prosmotr_vih(tabli* beg)
- {
- if (!beg)
- {
- cout << "список пустой" << endl;
- cin.get();
- return;
- }
- tabli* temp = beg;
- cout << "+———————————————————+————————————————————+———————————————————+———————————————————+ " << endl;
- cout << "| | | Количество Количество | " << endl;
- cout << "| Шифр группы | Средний бал +——————————+—————————+———————+————————— | " << endl;
- cout << "| | | Отл. | Хор. |Удовл. | Неуд. | " << endl;
- cout << "+———————————————————+————————————————————+——————————+—————————+———————+————————— + " << endl;
- while (temp)
- {
- print_vih(*temp);
- temp = temp->next;
- }
- cout << "+———————————————————+————————————————————+——————————+—————————+———————+——————————+ " << endl;
- cin.get();
- }//-------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void prosmotr_vh(tabli* beg)
- {
- int l=0;
- if (!beg)
- {
- cout << "список пустой" << endl;
- cin.get();
- return;
- }
- tabli* temp = beg;
- cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
- cout << "| | | | Количество Количество | | | " << endl;
- cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
- cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- while (temp)
- {
- cout << "|" << ++l << "|";
- print_vh(*temp);
- temp = temp->next;
- }
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- cin.get();
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void print_vih(const tabli& z)
- {
- cout << "|" << z.t.shg << setw(20 - (z.t.shg).length()) << "|";
- cout << z.t.srb << setw(20);
- cout << z.t.ot << setw(10 - (z.t.ot).length()) << "|";
- cout << z.t.xoro << setw(9 - (z.t.xoro).length()) << "|";
- cout << z.t.yd << setw(7 - (z.t.yd).length()) << "|";
- cout << z.t.noyd << setw(10 - (z.t.noyd).length()) << "|" << endl;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void print_vh(const tabli& z)
- {
- cout << z.t.shg << setw(20 - (z.t.shg).length()) << "|";
- cout << z.t.shd << setw(21 - (z.t.shd).length()) << "|";
- cout << z.t.ot << setw(11 - (z.t.ot).length()) << "|";
- cout << z.t.xoro << setw(10 - (z.t.xoro).length()) << "|";
- cout << z.t.yd << setw(8 - (z.t.yd).length()) << "|";
- cout << z.t.noyd << setw(11 - (z.t.noyd).length()) << "|";
- cout << z.t.prl << setw(33 - (z.t.prl).length()) << "|";
- cout << z.t.prz << setw(34 - (z.t.prz).length()) << "|" << endl;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void poiskshd(tabli* beg)
- {
- int k = 0;
- tabli* temp = beg;
- int fl = 0;
- char fa[dl];
- system("cls");
- if (!beg)
- {
- MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
- return;
- }
- cout << "Введите шифр дисциплины для поиска " << endl;
- cin >> fa;
- cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
- cout << "| | | | Количество Количество | | | " << endl;
- cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
- cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- while (temp)
- {
- if (fa == temp->t.shd)
- {
- cout << "|" << ++k << "|";
- print_vh(*temp);
- fl = 1;
- }
- temp = temp->next;
- }
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- if (fl != 1) {
- cout << "Дисципоина с таким шифром не найдена" << endl;
- }
- system("pause");
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- int read_file(string filename, tabli** beg, tabli** end)
- {
- cout << "Введите название файла" << endl;
- cin >> filename;
- ifstream fin(filename, ios::in);
- if (!fin)
- {
- cout << "Нет файла" << filename << endl;
- return 1;
- }
- tabli z;
- *beg = 0;
- fin.seekg(0, ios::beg);
- while (fin >> z.t.shg)
- {
- fin >> z.t.shd;
- fin >> z.t.ot;
- fin >> z.t.xoro;
- fin >> z.t.yd;
- fin >> z.t.noyd;
- fin >> z.t.prl;
- fin >> z.t.prz;
- fin >> z.t.srb;
- if (*beg)
- *end = dob(*end, z);
- else
- {
- *beg = dob_first(z); *end = *beg;
- }
- koli++;
- }
- cout << "Считывание прошло успешно" << endl;
- cin.get();
- cin.get();
- return 0;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- int write_file(string filename, tabli* temp)
- {
- cout << "Введите название файла" << endl;
- cin >> filename;
- ofstream fout(filename, ios_base::app); // открытие файла
- if (!fout)
- {
- cout << "Не могу открыть файл для записи" << endl;
- return 1;
- }
- while (temp)// пока temp!=0 выводим эл-ты в файл
- {
- fout << temp->t.shg << endl;
- fout << temp->t.shd << endl;
- fout << temp->t.ot << endl;
- fout << temp->t.xoro << endl;
- fout << temp->t.yd << endl;
- fout << temp->t.noyd << endl;
- fout << temp->t.prl << endl;
- fout << temp->t.prz << endl;
- temp = temp->next;
- }
- cout << "Данные сохранены в файле: " << filename << endl;
- cout << "==============================" << endl;
- cout << "Нажмите любую клавишу" << endl;
- cin.get();
- return 0;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void print_menu(int sym, const string items[], const int N_ITEMS)
- {
- for (int i = 1; i <= N_ITEMS; i++)
- {
- SetColor(14, 2);
- gotoxy((width / 2) - 10, (height / 2) + i - 3);// ставим меню в центр
- if (i == sym)
- {
- SetColor(3, 15);
- }
- cout << items[i - 1] << endl;
- SetColor(14, 2);
- }
- }
- void print_menu2(int sym, const string items[], const int N_ITEMS)
- {
- for (int i = 1; i <= N_ITEMS; i++)
- {
- SetColor(14, 2);
- if (i == sym)
- {
- SetColor(3, 15);
- }
- cout << items[i - 1] << endl;
- SetColor(14, 2);
- }
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- int menu(int& active, const string items[], int num_el) {
- wint_t buf;
- while (1)
- {
- cls();
- print_menu(active, items, num_el);
- buf = _getwch();
- switch (buf)
- {
- case up: // клавиша вверх
- if (active > 1) active--;
- break;
- case down: // клавиша вниз
- if (active < num_el) active++;
- break;
- case enter: // клавиша enter
- return active;
- case esc: // клавиша escape
- return -1;
- }
- }
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- int menu2(int& active, const string items[], int num_el)
- {
- wint_t buf;
- do
- {
- system("cls");
- print_menu2(active, items, num_el);
- buf = _getwch();
- switch (buf)
- {
- case up: // клавиша вверх
- if (active > 1) active--;
- break;
- case down: // клавиша вниз
- if (active < num_el) active++;
- break;
- case enter: // клавиша enter
- return active;
- case esc: // клавиша escape
- return -1;
- }
- } while (1);
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- int changeshd(tabli* beg, string& user_shd, string& new_user_shd)
- {
- tabli* temp = beg;
- while (temp != NULL)
- {
- if (temp->t.shd == user_shd)
- {
- temp->t.shd = new_user_shd;
- return 1;
- }
- else
- {
- temp = temp->next;
- }
- }
- return 0;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- int changeshg(tabli* beg, string& user_shg, string& new_user_shg)
- {
- tabli* temp = beg;
- while (temp != NULL)
- {
- if (temp->t.shg == user_shg)
- {
- temp->t.shg = new_user_shg;
- return 1;
- }
- else
- {
- temp = temp->next;
- }
- }
- return 0;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void poiskshg(tabli* beg)
- {
- tabli* temp = beg;
- int k = 0;
- int fl = 0;
- char fa[dl];
- system("cls");
- if (!beg)
- {
- MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
- return;
- }
- cout << "Введите шифр для поиска группы" << endl;
- cin >> fa;
- cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
- cout << "| | | | Количество Количество | | | " << endl;
- cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
- cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- while (temp)
- {
- if (fa == temp->t.shg)
- {
- cout << "|" << ++k << "|";
- print_vh(*temp);
- fl = 1;
- }
- temp = temp->next;
- }
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- if (fl != 1) {
- cout << "Группа с таким шифром не найдена" << endl;
- }
- system("pause");
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void SetColor(int text, int bg) {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, (WORD)((bg << 4) | text));
- }
- void schetsrb(tabli* beg)
- {
- if (!beg)
- {
- cout << "список пустой" << endl;
- cin.get();
- return;
- }
- tabli* temp = beg;
- while (temp)
- {
- temp->t.srb = (5 * stoi(temp->t.ot) + 4 * stoi(temp->t.xoro) + 3 * stoi(temp->t.yd) + 2 * stoi(temp->t.noyd)) / (stoi(temp->t.ot) + stoi(temp->t.xoro) + stoi(temp->t.yd) + stoi(temp->t.noyd));
- }
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void sortirovka_prz(tabli** beg)
- {
- tabli* temp_i = *beg,
- * temp_j = *beg;
- for (; temp_i; temp_i = temp_i->next)
- {
- for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
- {
- if (temp_i->t.prz < temp_j->t.prz)
- {
- swap(temp_i->t, temp_j->t);
- }
- }
- }
- cout << "Сортировка прошла успешно" << endl;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void sortirovka_prz1(tabli** beg)
- {
- tabli* temp_i = *beg,
- * temp_j = *beg;
- for (; temp_i; temp_i = temp_i->next)
- {
- for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
- {
- if (temp_i->t.prz > temp_j->t.prz)
- {
- swap(temp_i->t, temp_j->t);
- }
- }
- }
- cout << "Сортировка прошла успешно" << endl;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void sortirovka_prl(tabli** beg)
- {
- tabli* temp_i = *beg,
- * temp_j = *beg;
- for (; temp_i; temp_i = temp_i->next)
- {
- for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
- {
- if (temp_i->t.prl < temp_j->t.prl)
- {
- swap(temp_i->t, temp_j->t);
- }
- }
- }
- cout << "Сортировка прошла успешно" << endl;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void sortirovka_prl1(tabli** beg)
- {
- tabli* temp_i = *beg,
- * temp_j = *beg;
- for (; temp_i; temp_i = temp_i->next)
- {
- for (temp_j = temp_i; temp_j; temp_j = temp_j->next)
- {
- if (temp_i->t.prl > temp_j->t.prl)
- {
- swap(temp_i->t, temp_j->t);
- }
- }
- }
- cout << "Сортировка прошла успешно" << endl;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void gotoxy(int xpos, int ypos)
- {
- COORD scrn;
- HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
- scrn.X = xpos; scrn.Y = ypos;
- SetConsoleCursorPosition(hOuput, scrn);
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void cls()
- {
- HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD cd;
- cd.X = 0;
- cd.Y = 0;
- SetConsoleCursorPosition(hd, cd);
- }
- int write_file_binary(string filename, tabli* beg)
- {
- cout << "Введите название файла" << endl;
- cin >> filename;
- tabli* temp = beg;
- ofstream fout(filename + ".dat", ios::binary); // открытие файла
- if (!fout)
- {
- cout << "Не могу открыть файл для записи" << endl;
- return 1;
- }
- while (temp) {
- fout.write((char*)&temp->t, sizeof temp->t);
- temp = temp->next;
- }
- fout.close();
- cout << "Данные сохранены в файле: " << filename << endl;
- cout << "==============================" << endl;
- cout << "Нажмите любую клавишу" << endl;
- cin.get();
- return 0;
- }
- // ==========ЧТЕНИЕ ИЗ БИНАРНОГО ФАЙЛА==========
- int read_bin_file(string filename, tabli** beg, tabli** end)
- {
- cout << "Введите название файла" << endl;
- cin >> filename;
- ifstream fin(filename + ".dat", ios::binary);
- if (!fin) {
- MessageBox(0, L"Нет файла!", L"Ошибка", MB_ICONERROR | MB_SETFOREGROUND);
- return 1;
- }
- fin.seekg(ios_base::beg);
- tabli* t = new tabli;
- t->next = NULL;
- t->pred = NULL;
- *beg = 0;
- while (fin.read((char*)&t->t, sizeof t->t))
- {
- if (*beg)
- *end = dob(*end, *t);
- else {
- *beg = dob_first(*t);
- *end = *beg;
- }
- }
- fin.close();
- return 0;
- }
- //=========================================================
- void output(tabli* beg)
- {
- tabli* temp = beg;
- int i = 0;
- int k = 0;
- int temp_k;
- int temp_i;
- int key;
- if (!beg) {
- cout << L"Ошибка! Список пуст." << endl;
- system("pause");
- return;
- }
- while (temp) {
- i++;
- temp = temp->next;
- }
- if (i % 8 == 0)
- temp_k = i / 8;
- else
- temp_k = i / 8 + 1;
- cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
- cout << "| | | | Количество Количество | | | " << endl;
- cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
- cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- temp = beg;
- if (i > 7)
- temp_i = 8;
- else temp_i = i;
- for (i = 0; i != temp_i; i++) {
- cout << "|" << ++k << "|";
- print_vh(*temp);
- temp = temp->next;
- if (i == temp_i - 1)
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- }
- while (1) {
- key = _getch();
- switch (key) {
- case 73:
- if (k == 0)
- break;
- system ("cls");
- cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
- cout << "| | | | Количество Количество | | | " << endl;
- cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
- cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- --k;
- temp = beg;
- i = 0;
- while (((k - 1) * 8 != i) && (temp)) {
- i++;
- temp = temp->next;
- }
- while (((i % 8 != 0) || ((k - 1) * 8 == i)) && (temp)) {
- i++;
- print_vh(*temp);
- temp = temp->next;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- }
- if ((i % 8 == 0) || (!temp))
- gotoxy(0, 3 + 2 * (i - (k - 1) * 8));
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- break;
- case 81:
- if (k == temp_k)
- break;
- system("cls");
- cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
- cout << "| | | | Количество Количество | | | " << endl;
- cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
- cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- ++k;
- temp = beg;
- i = 0;
- while (temp) {
- i++;
- temp = temp->next;
- }
- if (i % 8 == 0)
- temp_k = i / 8;
- else
- temp_k = i / 8 + 1;
- temp = beg;
- if (i > 7)
- temp_i = 8;
- else temp_i = i;
- for (i = 0; i != temp_i; i++) {
- cout << "|" << ++k << "|";
- print_vh(*temp);
- temp = temp->next;
- if (i == temp_i - 1)
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- }
- if ((i % 8 == 0) || (!temp))
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- break;
- case 27:
- return;
- default:
- break;
- }
- }
- }
- /*tabli* list(tabli* beg, int active, int page, int k)
- {
- tabli* temp = beg,
- * buf_temp = beg,
- * buf_el = beg,
- * first_temp = beg;
- int c = 0,
- key = 0,
- extreme_page = 2,// переменная для первой страницы, если это первая страница, тогда 1, в остальных случаях = 2
- first_k = 0,
- k_this_page = 0;
- int num_del = 0; // номер для удаления
- k = 0;
- page = 1;
- active = 1;
- while (1)
- {
- if (!beg)
- {
- MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
- return beg;
- }
- if (k != koli + 1 && extreme_page != 1)
- {
- k_this_page = 0;
- cout << "+—+———————————————————+————————————————————+—————————————————————————————————————— +————————————————————————————————+—————————————————————————————————+ " << endl;
- cout << "| | | | Количество Количество | | | " << endl;
- cout << "|№| Шифр группы | Шифр дисциплины |——————————+—————————+———————+————————— | пропущено лекций | пропущено практических занятий + " << endl;
- cout << "| | | | Отл. | Хор. |Удовл. | Неуд. | | | " << endl;
- cout << "+—+———————————————————+————————————————————+——————————+—————————+———————+——————————+————————————————————————————————+—————————————————————————————————+ " << endl;
- do {
- k_this_page++;
- // вытаскиваем первый элемент текущей страницы
- if (k % 5 == 0) {
- first_k = k;
- first_temp = temp;
- }
- // находим первый элемент с предыдущей страницы
- if (k % 5 == 0 && page != 1) {
- buf_el = temp;
- for (int j = 0; j < 5; j++, temp = temp->pred) {
- buf_temp = temp->pred;
- }
- temp = buf_el;
- }
- cout << "|" << ++k << "|";
- print_vh(*temp);
- temp = temp->next;
- } while (temp && k % 5 != 0);
- cout << "+———————————————————+————————————————————+——————————————————+————————————————+——————————————————+———————————————+" << endl;
- cout << "Страница " << page << " из " << ceil(koli / 5);
- }
- c = _getwch();
- if (c == esc) return 0;
- key = _getwch();
- switch (key) {
- case right_btn:
- extreme_page = 2;
- if (k + 1 != koli) {
- page++;
- }
- else {
- k = first_k;
- temp = first_temp;
- }
- system("cls");
- break;
- case left_btn:
- if (page != 1) {
- system("cls");
- k -= k_this_page + 5;
- page--;
- temp = buf_temp;
- }
- else extreme_page = 1;
- break;
- }
- }
- }*
- //-----------------------------------------------------------------------------------------------------
- /*tabli* delete_el(tabli* beg)
- {
- tabli* temp;
- tabli* buf;
- int num_del = 0,
- count = 0;
- if (!beg) {
- MessageBox(0, L"Список пуст", L"Уведомление", MB_ICONINFORMATION | MB_SETFOREGROUND);
- return 0;
- }
- temp = beg;
- cout << "Введите номер элемента,который хотите удалить" << endl;
- cin >> num_del;
- // если один элемент в списке
- if (beg->next == 0) {
- delete temp;
- return 0;
- }
- while (temp) {
- if (num_del == ++count) { // если введённый номер совпал с шифром задания
- buf = temp->next;
- // если удаляется второй элемент
- if (temp->pred == 0) {
- buf->pred = 0;
- delete temp;
- return buf;
- }
- if (buf != 0) buf->pred = temp->pred; // если следующий элемент не 0
- buf = temp->pred;
- buf->next = temp->next;
- delete temp;
- return beg;
- }
- temp = temp->next;
- }
- MessageBox(0, L"Произошла ошибка!", L"Ошибка", MB_ICONERROR | MB_SETFOREGROUND);
- return beg;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment