Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <string.h>
- #include <windows.h>
- using namespace std;
- struct student {
- string surname;
- string name;
- string patronymic;
- unsigned int age;
- unsigned int progress;
- student* next;
- };
- bool flag = false;
- double temp;
- int Search(student* List){
- string su;
- cin>>su;
- student* l;
- l = List;
- while(l -> next != NULL){
- if(l ->surname==su){
- cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
- }
- l = l -> next;
- }
- }
- bool checkValid(){ // Проверка правильности ввода данных
- char str[82];
- temp = 0;
- bool dot = false;
- int stepen = 0;
- for(int i = 0; i < 82;i++){
- str[i] = '@';
- }
- std::cin >> str;
- for(int i = 0; i < strlen(str);i++){
- if(isdigit(str[i]) || str[i] == '.'){ // проверка является ли символ буквой
- if(str[i] == '.' && dot == false){
- dot = true;
- }
- if(dot == true && str[i] != '.'){ // после точки
- stepen++;
- std::cout << "step ++ \n";
- int zn = pow(10,stepen);
- temp = (temp*10 + (str[i] - '0'))/zn;
- }
- if(isdigit(str[i]) && dot == false){ // до точки
- temp = temp*10 + (str[i] - '0');
- }
- }else{
- std::cout << "\n";
- std::cout << "Error! Invalid value\n";
- std::cout << "Input value again : \n";
- return false;
- }
- }
- return true;
- }
- void init(student* List){
- cout << "Введіть Прізвище: ";
- cin >> List->surname;
- cout << "Введіть Ім'я: ";
- cin >> List->name;
- cout << "Введіть По-батькові: ";
- cin >> List->patronymic;
- cout << "Введіть вік";
- while(checkValid() == false){}
- List->age = temp;
- cout << "Введіть Середній бал";
- while (checkValid() == false) {}
- if (temp < 0 || temp > 100) {
- cout << "Ошибка";
- List->progress = 0;
- }
- else {
- List->progress = temp;
- }
- List -> next = NULL;
- flag = true;
- }
- void print(student* List){
- student*p;
- p = List;
- if(flag == true){
- cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік\t" << "Середній бал\n";
- do{
- cout << p->surname << "\t" << p->name << "\t" << p->patronymic << "\t" << p->age << "\t" << p->progress <<"\n";
- p = p -> next;
- }while (p != NULL);
- }else{
- cout << "Список порожній\n";
- }
- }
- void Add_Beg(student* List){
- if(flag == true){
- student* tmp;
- student* p;
- tmp = new student;
- p = List->next;
- List -> next = tmp;
- tmp->name = List->name;
- tmp->surname = List->surname;
- tmp->patronymic = List->patronymic;
- tmp->age = List->age;
- tmp->progress = List->progress;
- tmp->next = p;
- cout << "Введіть Прізвище: ";
- cin >> List->surname;
- cout << "Введіть Ім'я: ";
- cin >> List->name;
- cout << "Введіть По-батькові: ";
- cin >> List->patronymic;
- cout << "Введіть вік";
- while(checkValid() == false){}
- List->age = temp;
- cout << "Введіть Середній бал";
- while (checkValid() == false) {}
- if (temp < 0 || temp > 100) {
- cout << "Ошибка";
- List->progress = 0;
- }
- else {
- List->progress = temp;
- }
- }else{
- init(List);
- }
- }
- void Sort(student* List){
- student* p = new student;
- if (List != NULL) {
- while (List->next != NULL) {
- p = List->next;
- do {
- if (p->surname < List->surname) {
- string tmp = p->surname;
- p->surname = List->surname;
- List->surname = tmp;
- }
- p = p->next;
- } while (p != NULL);
- List = List->next;
- }
- }
- }
- void addLast(student* List){
- if(flag == true){
- student* tmp;
- student* p;
- tmp = new student;
- tmp -> next = NULL;
- p = List;
- while (p -> next != NULL){
- p = p -> next;
- }
- p -> next = tmp;
- cout << "Введіть Прізвище: ";
- cin >> tmp->surname;
- cout << "Введіть Ім'я: ";
- cin >> tmp->name;
- cout << "Введіть По-батькові: ";
- cin >> tmp->patronymic;
- cout << "Введіть вік";
- while(checkValid() == false){}
- tmp->age = temp;
- cout << "Введіть Середній бал";
- while (checkValid() == false) {}
- if (temp < 0 || temp > 100) {
- cout << "Ошибка";
- tmp->progress = 0;
- }
- }else{
- init(List);
- }
- }
- void addAfter(student* List){
- if(flag = true){
- student* tmp;
- student* l;
- student* p;
- tmp = new student;
- bool flag_after = false;
- l = List;
- string prev;
- cin >> prev;
- while(l -> next != NULL){
- l = l -> next;
- if(l -> surname == prev){
- p = l -> next;
- l -> next = tmp;
- cout << "Введіть Прізвище: ";
- cin >> tmp->surname;
- cout << "Введіть Ім'я: ";
- cin >> tmp->name;
- cout << "Введіть По-батькові: ";
- cin >> tmp->patronymic;
- cout << "Введіть вік";
- while(checkValid() == false){}
- tmp->age = temp;
- cout << "Введіть Середній бал";
- while (checkValid() == false) {}
- if (temp < 0 || temp > 100) {
- cout << "Ошибка";
- tmp->progress = 0;
- }
- tmp -> next = p;
- flag_after = true;
- break;
- }
- }
- if(flag == false){
- cout << "Cписок не создан\n";
- }
- }else{
- init(List);
- }
- }
- void progress(student* List){
- if(flag == true){
- student* l;
- l = List;
- cout << "Відмінно (100 - 90)\n";
- cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
- while(l -> next != NULL){
- l = l -> next;
- if(l ->progress >= 90){
- cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
- }
- }
- l = List;
- cout << "Добре (70 - 89)\n";
- cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
- while(l -> next != NULL){
- l = l -> next;
- if(l ->progress >= 70 && l ->progress < 90){
- cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
- }
- }
- l = List;
- cout << "Задовільно (50 - 69)\n";
- cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
- while(l -> next != NULL){
- l = l -> next;
- if(l ->progress >= 50 && l ->progress < 70){
- cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
- }
- }
- l = List;
- cout << "Не задовільно (0 - 49)\n";
- cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
- while(l -> next != NULL){
- l = l -> next;
- if(l ->progress >= 0 && l ->progress < 50){
- cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
- }
- }
- }else{
- cout << "Порожньо!\n";
- }
- }
- void Delete(student* List){ //удаление студента
- string name;
- student* temp=List;
- student* last=List;
- bool flag=false;
- cout << "Вкажіть прізвище студентів, яких бажаєте видалити: ";
- cin >> name;
- while(last!=NULL){
- if(last->surname==name){
- while((temp->next!=last)&&(temp!=last))
- temp=temp->next;
- if(temp==last){
- List=last->next;
- delete &List;
- }
- else{
- temp->next=last->next;
- delete &last;
- }
- flag=true;
- }
- last=last->next;
- }
- if(flag==false)
- cout << "Жодного студента з такими даними не знайдено!" << endl;
- else cout << "Студентів видалено!" << endl;
- }
- int main(){
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- student* first = new student;
- string fam;
- int flag;
- while(true){
- cout<<endl;
- cout << "Меню: " << endl;
- cout << "1.Перегляд усієї групи" << endl;
- cout << "2.У початок" << endl;
- cout << "3.У кінець" << endl;
- cout << "4.Після учня з прізвищем" << endl;
- cout << "5.Пошук за прізвищем" << endl;
- cout << "6.Друк за балами" << endl;
- cout << "7.Видалення за прізвищем" << endl;
- cout << "8 Вихід\n";
- cin>>flag;
- switch(flag){
- case 1:
- print(first);
- break;
- case 2:
- Add_Beg(first);
- break;
- case 3:
- addLast(first);
- break;
- case 4:
- addAfter(first);
- break;
- case 5:
- Search(first);
- break;
- case 6:
- progress(first);
- break;
- case 7:
- Delete(first);
- break;
- case 8:
- return 0;
- default: cout<<"1-8!";
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement