Добавил:
chachshin_denis
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:1-2 курс (сорян, лень разбирать) / CourseWork_0391_Chashchin_Denis
.cpp#include <iostream>
#include <fstream>
#include <cstring>
#include <conio.h>
#include <string>
using namespace std;
struct list
{
char fio[50];
int ocenki[5];
int step;
list* next;
float umm;
bool ploh = false;
};
struct group
{
list* top = nullptr;
list* back = nullptr;
group* next;
int ngroup;
float neumn;
};
void ConsoleInput(group*& top, group*& back, char fio[50], int ngr)
{
group* buf = nullptr, * buf2 = nullptr;
if (back == nullptr)
{
back = new group;
top = back;
top->next = nullptr;
back->ngroup = ngr;
back->top = new list;
back->back = back->top;
strcpy_s(back->back->fio, fio);
ConsoleAddInfo(back);
top->back->next = nullptr;
}
else if (ngr < top->ngroup)
{
buf = new group;
buf->next = top;
top = buf;
top->ngroup = ngr;
top->top = new list;
top->back = top->top;
strcpy_s(top->back->fio, fio);
ConsoleAddInfo(top);
top->back->next = nullptr;
}
else if (ngr > back->ngroup)
{
back->next = new group;
back = back->next;
back->ngroup = ngr;
back->top = new list;
back->back = back->top;
strcpy_s(back->back->fio, fio);
ConsoleAddInfo(back);
back->back->next = nullptr;
back->next = nullptr;
}
else
{
buf = top;
while (true)
{
if (buf->ngroup == ngr)
{
buf->back->next = new list;
buf->back = buf->back->next;
strcpy_s(buf->back->fio, fio);
ConsoleAddInfo(buf);
buf->back->next = nullptr;
break;
}
else if (buf->next == nullptr)
break;
else if (ngr < buf->next->ngroup)
{
buf2 = buf->next;
buf->next = new group;
buf->next->next = buf2;
buf = buf->next;
buf->ngroup = ngr;
buf->top = new list;
buf->back = buf->top;
strcpy_s(buf->back->fio, fio);
ConsoleAddInfo(buf);
buf->back->next = nullptr;
break;
}
buf = buf->next;
}
}
}
void FileInput(group*& top, group*& back, char fio[50], int ngr)
{
group* buf = nullptr, * buf2 = nullptr;
ifstream fin("input.txt", ios_base::in);
if (fin)
{
fin.getline(fio, 50);
fin >> ngr;
while (fio[0] != '0')
{
if (back == nullptr)
{
back = new group;
top = back;
top->next = nullptr;
back->ngroup = ngr;
back->top = new list;
back->back = back->top;
strcpy_s(back->back->fio, fio);
for (int i = 0; i < 5; i++)
fin >> back->back->ocenki[i];
fin >> back->back->step;
top->back->next = nullptr;
}
else if (ngr < top->ngroup)
{
buf = new group;
buf->next = top;
top = buf;
top->ngroup = ngr;
top->top = new list;
top->back = top->top;
strcpy_s(top->back->fio, fio);
for (int i = 0; i < 5; i++)
fin >> top->back->ocenki[i];
fin >> top->back->step;
top->back->next = nullptr;
}
else if (ngr > back->ngroup)
{
back->next = new group;
back = back->next;
back->ngroup = ngr;
back->top = new list;
back->back = back->top;
strcpy_s(back->back->fio, fio);
for (int i = 0; i < 5; i++)
fin >> back->back->ocenki[i];
fin >> back->back->step;
back->back->next = nullptr;
back->next = nullptr;
}
else
{
buf = top;
while (true)
{
if (buf->ngroup == ngr)
{
buf->back->next = new list;
buf->back = buf->back->next;
strcpy_s(buf->back->fio, fio);
for (int i = 0; i < 5; i++)
fin >> buf->back->ocenki[i];
fin >> buf->back->step;
buf->back->next = nullptr;
break;
}
else if (buf->next == nullptr)
break;
else if (ngr < buf->next->ngroup)
{
buf2 = buf->next;
buf->next = new group;
buf->next->next = buf2;
buf = buf->next;
buf->ngroup = ngr;
buf->top = new list;
buf->back = buf->top;
strcpy_s(buf->back->fio, fio);
for (int i = 0; i < 5; i++)
fin >> buf->back->ocenki[i];
fin >> buf->back->step;
buf->back->next = nullptr;
break;
}
buf = buf->next;
}
}
fin.getline(fio, 50);
fin.getline(fio, 50);
fin >> ngr;
}
fin.close();
}
}
void ConsoleAddInfo(group*& buf)
{
cout << "Введите набор из пяти оценок за последнюю сессию " << endl;
for (int i = 0; i < 5; i++)
cin >> buf->back->ocenki[i];
cout << "Введите размер стипендии " << endl;
cin >> buf->back->step;
}
void editStudentInfo(group*& top, group*& back, char fio[50])
{
list* buf2 = nullptr, * buf3 = nullptr;
group* buf = nullptr, * buf1 = nullptr;
int change, change1, ngr;
cout << "Введите имя студента " << endl;
cin.getline(fio, 50);
cin.getline(fio, 50);
cout << "Введите номер группы " << endl;
cin >> ngr;
cout << "1-Удаление студента из списка " << endl;
cout << "2-Добавление студента " << endl;
cout << "3-Редактирование данных о студенте" << endl;
cout << "4-Выход " << endl;
cout << "Ваш выбор(1-3) " << endl;
cin >> change;
buf = top;
switch (change)
{
case 1:
while (buf != nullptr)
{
if (buf->ngroup == ngr)
{
buf2 = buf->top;
if (strcmp(buf2->fio, fio) == 0)
{
buf2 = buf->top;
buf->top = buf2->next;
delete buf2;
return;
}
}
else
{
buf = buf->next;
continue;
}
while (buf2->next != nullptr)
{
if (strcmp(buf2->next->fio, fio) == 0)
{
if (buf2->next == buf->back)
{
buf->back = buf2;
buf3 = buf2->next;
buf2->next = nullptr;
delete buf3;
return;
}
buf3 = buf2->next;
buf2->next = buf3->next;
delete buf3;
return;
}
buf2 = buf2->next;
}
}
cout << "Студент удален " << endl;
break;
case 2:
ConsoleInput(top, back, fio, ngr);
cout << "Студент добавлен " << endl;
break;
case 3:
cout << "1-Изменить группу " << endl;
cout << "2-Изменить оценки " << endl;
cout << "3-Изменить стипендию " << endl;
cout << "4-Выход " << endl;
cout << "Ваш выбор(1-3)" << endl;
cin >> change1;
switch (change1)
{
case 1:
cout << "Введите номер группы " << endl;
while (buf != nullptr)
{
if (ngr == buf->ngroup)
{
buf2 = buf->top;
if (strcmp(buf2->fio, fio) == 0)
{
buf3 = buf2;
buf->top = buf2->next;
}
while (buf2->next != nullptr)
{
if (strcmp(buf2->next->fio, fio) == 0)
{
buf3 = buf2->next;
buf2->next = buf3->next;
if (buf->back = buf3)
{
buf->back = buf2;
}
}
buf2 = buf2->next;
}
}
buf = buf->next;
}
cin >> ngr;
if (buf3 == nullptr)
cout << "1";
else if (ngr < top->ngroup)
{
buf = new group;
buf->next = top;
top = buf;
top->ngroup = ngr;
top->top = buf3;
buf3->next = nullptr;
return;
}
else if (ngr > back->ngroup)
{
back->next = new group;
back = back->next;
back->ngroup = ngr;
back->top = buf3;
buf3->next = nullptr;
return;
}
else
{
buf = top;
while (1)
{
if (buf->ngroup == ngr)
{
buf->back->next = buf3;
buf3->next = nullptr;
break;
}
else if (buf->next == nullptr)
break;
else if (ngr < buf->next->ngroup)
{
buf1 = buf->next;
buf->next = new group;
buf->next->next = buf1;
buf = buf->next;
buf->ngroup = ngr;
buf->top = buf3;
buf->back = buf->top;
buf->back->next = nullptr;
break;
}
buf = buf->next;
}
}
break;
case 2:
buf = top;
cout << "Введите оценки " << endl;
while (buf != nullptr)
{
buf2 = buf->top;
while (buf2 != nullptr)
{
if (strcmp(buf2->fio, fio) == 0)
{
for (int i = 0; i < 5; i++)
{
cin >> buf2->ocenki[i];
return;
}
}
buf2 = buf2->next;
}
buf = buf->next;
}
break;
case 3:
cout << "Введите стипендию " << endl;
while (buf != nullptr)
{
buf2 = buf->top;
while (buf2 != nullptr)
{
if (strcmp(buf2->fio, fio) == 0)
{
cin >> buf2->step;
}
buf2 = buf2->next;
}
buf = buf->next;
}
break;
case 4:
break;
}
return;
buf2 = buf2->next;
buf = buf->next;
case 4:
break;
}
}
void task1(group* top) //Вывести в порядке следования номеров групп фамилии тех студентов, у которых личный средний балл не превышает заданного значения
{
list* buf = nullptr;
group* buf1 = nullptr;
float pc;
cout << "Введите значение " << endl;
cin >> pc;
float n = 0;
buf1 = top;
while (buf1 != nullptr)
{
buf = buf1->top;
while (buf != nullptr)
{
n = 0;
for (int i = 0; i < 5; i++)
{
buf->umm += buf->ocenki[i];
}
buf->umm = buf->umm / 5;
buf = buf->next;
}
buf1 = buf1->next;
}
buf1 = top;
while (buf1 != nullptr)
{
cout << "Группа " << buf1->ngroup << endl;
buf = buf1->top;
if (buf->umm < pc)
{
cout << buf1->ngroup << " " << endl;
}
buf1 = buf1->next;
}
}
void task2(group* top) //Вывести на экран в порядке возрастания номера групп, в которых процент троечников и двоечников превышает заданное с клавиатуры значение
{
list* buf = nullptr;
group* buf1 = nullptr;
float pc;
cout << "Введите процент хорошистов и отличников " << endl;
cin >> pc;
int n = 0, k = 0, s = 0;
int gg;
buf1 = top;
while (buf1 != nullptr)
{
buf = buf1->top;
while (buf != nullptr)
{
n = 0;
s++;
for (int i = 0; i < 5; i++)
{
if (buf->ocenki[i] < 4)
{
n++;
break;
}
if (n > 1)
{
buf->ploh = true;
}
if (buf->ploh == true)
{
k++;
}
}
buf = buf->next;
}
buf1->neumn = k / s * 100;
buf1 = buf1->next;
}
buf1 = top;
while (buf1 != nullptr)
{
if (buf1->neumn > pc)
{
cout << buf1->ngroup << " " << endl;
}
buf1 = buf1->next;
}
}
void showConsole(group* top)
{
group* buf = nullptr;
list* buf1 = nullptr;
buf = top;
while (buf != nullptr)
{
cout << buf->ngroup << endl;
buf1 = buf->top;
while (buf1 != nullptr)
{
cout << buf1->fio << std::endl;
for (int i = 0; i < 5; i++)
{
cout << buf1->ocenki[i] << " ";
}
cout << endl;
cout << buf1->step << endl;
buf1 = buf1->next;
}
buf = buf->next;
}
}
void FileShow(group* top)
{
group* buf = nullptr;
list* buf1 = nullptr;
ofstream fout("output.txt");
if (fout)
{
buf = top;
while (buf != nullptr)
{
fout << "Группа " << buf->ngroup << endl;
buf1 = buf->top;
while (buf1 != nullptr)
{
fout << buf1->fio << endl;
for (int i = 0; i < 5; i++)
{
fout << buf1->ocenki[i] << " ";
}
fout << endl;
fout << buf1->step << endl;
buf1 = buf1->next;
}
buf = buf->next;
}
fout.close();
}
}
void DelGroup(group*& top, group*& back)
{
int ngr;
cout << "Введите номер группы для удаления " << endl;
cin >> ngr;
group* buf = nullptr, * buf1 = nullptr;
list* buf2 = nullptr, * buf3 = nullptr;
buf = top;
while (buf != nullptr)
{
if (top->ngroup == ngr)
{
buf2 = top->top;
while (buf2 != nullptr)
{
buf3 = buf2->next;
delete buf2;
buf2 = buf3;
}
top = top->next;
delete buf;
break;
}
if (buf->next == nullptr)
break;
if (buf->next->ngroup == ngr)
{
if (buf->next == back)
{
back = buf;
buf1 = buf->next;
buf2 = buf->next->top;
while (buf2 != nullptr)
{
buf3 = buf2->next;
delete buf2;
buf2 = buf3;
}
delete buf1;
buf->next = nullptr;
break;
}
else
{
buf1 = buf->next;
buf->next = buf1->next;
buf2 = buf1->top;
while (buf2 != nullptr)
{
buf3 = buf2->next;
delete buf2;
buf2 = buf3;
}
delete buf1;
break;
}
}
buf = buf->next;
}
}
int main()
{
setlocale(LC_ALL, "RUSSIAN");
group* top = nullptr, * back = nullptr, * buf1 = nullptr;
list* buf3 = nullptr, * buf2 = nullptr;
int change = 0;
int ngr = 0, k, x;
char fio[50];
cout << "1-Консольный ввод списка " << endl;
cout << "2-Файловый ввод списка " << endl;
cout << "3-Редактирование данных о студенте " << endl;
cout << "4-Показать список " << endl;
cout << "5-Удаление группы из списка " << endl;
cout << "6-Задание №25 " << endl;
cout << "7-Задание №15 " << endl;
cout << "8-Файловый вывод " << endl;
do
{
cout << "Ваш выбор " << endl;
cin >> change;
switch (change)
{
case 1:
cout << "Введите ФИО студента " << endl;
cin.getline(fio, 50);
cin.getline(fio, 50);
cout << "Введите номер группы " << endl;
cin >> ngr;
while (fio[0] != '0')
{
ConsoleInput(top, back, fio, ngr);
cout << "Введите ФИО студента " << endl;
cin.getline(fio, 50);
cin.getline(fio, 50);
cout << "Введите номер группы " << endl;
cin >> ngr;
}
break;
case 2:
FileInput(top, back, fio, ngr);
break;
case 3:
editStudentInfo(top, back, fio);
break;
case 4:
if (top == nullptr)
cout << "Данные о студентах отсутствуют " << endl;
else
showConsole(top);
break;
case 5:
DelGroup(top, back);
break;
case 6:
task1(top);
break;
case 7:
task2(top);
break;
case 8:
FileShow(top);
break;
};
} while (change != 0);
return 0;
}
Соседние файлы в папке 1-2 курс (сорян, лень разбирать)