Advertisement
lashrone1

new

May 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <string.h>
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. struct student {
  10.     string surname;
  11.     string name;
  12.     string patronymic;
  13.     unsigned int age;
  14.  
  15.     unsigned int progress;
  16.     student* next;
  17. };
  18.  
  19. bool flag = false;
  20.  
  21.  
  22. double temp;
  23.  
  24. int Search(student* List){
  25.     string su;
  26.     cin>>su;
  27.     student* l;
  28.     l = List;
  29.     while(l -> next != NULL){
  30.             if(l ->surname==su){
  31.                 cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
  32.             }
  33.             l = l -> next;
  34.         }
  35.  
  36.  }
  37.  
  38. bool checkValid(){          // Проверка правильности ввода данных
  39.     char str[82];
  40.     temp = 0;
  41.     bool dot = false;
  42.     int stepen = 0;
  43.  
  44.     for(int i = 0; i < 82;i++){
  45.         str[i] = '@';
  46.     }
  47.  
  48.     std::cin >> str;
  49.  
  50.  
  51.  
  52.   for(int i = 0; i < strlen(str);i++){
  53.         if(isdigit(str[i]) || str[i] == '.'){          // проверка является ли символ буквой
  54.             if(str[i] == '.' && dot == false){
  55.                 dot = true;
  56.  
  57.             }
  58.  
  59.             if(dot == true && str[i] != '.'){       // после точки
  60.                 stepen++;
  61.                 std::cout << "step ++ \n";
  62.                 int zn = pow(10,stepen);
  63.                 temp = (temp*10 + (str[i] - '0'))/zn;
  64.             }
  65.  
  66.             if(isdigit(str[i]) && dot == false){  // до точки
  67.                temp = temp*10 + (str[i] - '0');
  68.                }
  69.  
  70.         }else{
  71.              std::cout << "\n";
  72.              std::cout << "Error! Invalid value\n";
  73.              std::cout << "Input value again : \n";
  74.              return false;
  75.          }
  76.  
  77.     }
  78.  
  79. return true;
  80. }
  81.  
  82. void init(student* List){
  83.     cout << "Введіть Прізвище: ";
  84.     cin >> List->surname;
  85.     cout << "Введіть Ім'я: ";
  86.     cin >> List->name;
  87.     cout << "Введіть По-батькові: ";
  88.     cin >> List->patronymic;
  89.  
  90.     cout << "Введіть вік";
  91.     while(checkValid() == false){}
  92.     List->age = temp;
  93.  
  94.     cout << "Введіть Середній бал";
  95.     while (checkValid() == false) {}
  96.     if (temp < 0 || temp > 100) {
  97.         cout << "Ошибка";
  98.         List->progress = 0;
  99.     }
  100.     else {
  101.         List->progress = temp;
  102.     }
  103.  
  104.     List -> next = NULL;
  105.  
  106.     flag = true;
  107.  
  108. }
  109.  
  110. void print(student* List){
  111.     student*p;
  112.     p = List;
  113.  
  114.     if(flag == true){
  115.         cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік\t" << "Середній бал\n";
  116.  
  117.         do{
  118.             cout << p->surname << "\t" << p->name << "\t" << p->patronymic << "\t" << p->age << "\t" << p->progress <<"\n";
  119.             p = p -> next;
  120.         }while (p != NULL);
  121.     }else{
  122.         cout << "Список порожній\n";
  123.     }
  124.  
  125. }
  126.  
  127. void Add_Beg(student* List){
  128.  
  129.     if(flag == true){
  130.  
  131.         student* tmp;
  132.         student* p;
  133.  
  134.         tmp = new student;
  135.  
  136.         p = List->next;
  137.         List -> next  = tmp;
  138.  
  139.         tmp->name = List->name;
  140.         tmp->surname = List->surname;
  141.         tmp->patronymic = List->patronymic;
  142.         tmp->age = List->age;
  143.         tmp->progress = List->progress;
  144.         tmp->next = p;
  145.  
  146.         cout << "Введіть Прізвище: ";
  147.         cin >> List->surname;
  148.         cout << "Введіть Ім'я: ";
  149.         cin >> List->name;
  150.         cout << "Введіть По-батькові: ";
  151.         cin >> List->patronymic;
  152.  
  153.         cout << "Введіть вік";
  154.         while(checkValid() == false){}
  155.         List->age = temp;
  156.  
  157.         cout << "Введіть Середній бал";
  158.         while (checkValid() == false) {}
  159.         if (temp < 0 || temp > 100) {
  160.             cout << "Ошибка";
  161.             List->progress = 0;
  162.         }
  163.         else {
  164.             List->progress = temp;
  165.         }
  166.  
  167.         }else{
  168.         init(List);
  169.         }
  170. }
  171.  
  172. void Sort(student* List){
  173.     student* p = new student;
  174.     if (List != NULL) {
  175.         while (List->next != NULL) {
  176.             p = List->next;
  177.  
  178.             do {
  179.                 if (p->surname < List->surname) {
  180.                     string tmp = p->surname;
  181.                     p->surname = List->surname;
  182.                     List->surname = tmp;
  183.                 }
  184.  
  185.                 p = p->next;
  186.             } while (p != NULL);
  187.  
  188.             List = List->next;
  189.         }
  190.     }
  191. }
  192.  
  193. void addLast(student* List){
  194.     if(flag == true){
  195.  
  196.         student* tmp;
  197.         student* p;
  198.  
  199.         tmp = new student;
  200.  
  201.         tmp -> next = NULL;
  202.         p = List;
  203.  
  204.         while (p -> next != NULL){
  205.             p = p -> next;
  206.         }
  207.  
  208.         p -> next = tmp;
  209.         cout << "Введіть Прізвище: ";
  210.         cin >> tmp->surname;
  211.         cout << "Введіть Ім'я: ";
  212.         cin >> tmp->name;
  213.         cout << "Введіть По-батькові: ";
  214.         cin >> tmp->patronymic;
  215.  
  216.         cout << "Введіть вік";
  217.         while(checkValid() == false){}
  218.         tmp->age = temp;
  219.  
  220.         cout << "Введіть Середній бал";
  221.         while (checkValid() == false) {}
  222.         if (temp < 0 || temp > 100) {
  223.             cout << "Ошибка";
  224.             tmp->progress = 0;
  225.         }
  226.     }else{
  227.         init(List);
  228.     }
  229. }
  230.  
  231. void addAfter(student* List){
  232.  
  233.     if(flag = true){
  234.         student* tmp;
  235.         student* l;
  236.         student* p;
  237.         tmp = new student;
  238.         bool flag_after = false;
  239.  
  240.         l = List;
  241.  
  242.         string prev;
  243.  
  244.         cin >> prev;
  245.  
  246.         while(l -> next != NULL){
  247.             l = l -> next;
  248.             if(l -> surname == prev){
  249.                 p = l -> next;
  250.                 l -> next = tmp;
  251.  
  252.                 cout << "Введіть Прізвище: ";
  253.                 cin >> tmp->surname;
  254.                 cout << "Введіть Ім'я: ";
  255.                 cin >> tmp->name;
  256.                 cout << "Введіть По-батькові: ";
  257.                 cin >> tmp->patronymic;
  258.  
  259.                 cout << "Введіть вік";
  260.                 while(checkValid() == false){}
  261.                 tmp->age = temp;
  262.  
  263.                 cout << "Введіть Середній бал";
  264.                 while (checkValid() == false) {}
  265.                 if (temp < 0 || temp > 100) {
  266.                     cout << "Ошибка";
  267.                     tmp->progress = 0;
  268.                 }
  269.  
  270.                 tmp -> next = p;
  271.  
  272.                 flag_after = true;
  273.                 break;
  274.             }
  275.         }
  276.  
  277.         if(flag == false){
  278.             cout << "Cписок не создан\n";
  279.         }
  280.     }else{
  281.         init(List);
  282.     }
  283.  
  284. }
  285.  
  286.  
  287.  
  288. void progress(student* List){
  289.     if(flag == true){
  290.         student* l;
  291.         l = List;
  292.  
  293.         cout << "Відмінно (100 - 90)\n";
  294.         cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
  295.  
  296.         while(l -> next != NULL){
  297.             l = l -> next;
  298.             if(l ->progress >= 90){
  299.                 cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
  300.             }
  301.         }
  302.  
  303.         l = List;
  304.  
  305.         cout << "Добре (70 - 89)\n";
  306.         cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
  307.  
  308.         while(l -> next != NULL){
  309.             l = l -> next;
  310.             if(l ->progress >= 70 && l ->progress < 90){
  311.                 cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
  312.             }
  313.         }
  314.  
  315.         l = List;
  316.  
  317.         cout << "Задовільно (50 - 69)\n";
  318.         cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
  319.  
  320.         while(l -> next != NULL){
  321.             l = l -> next;
  322.             if(l ->progress >= 50 && l ->progress < 70){
  323.                 cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
  324.             }
  325.         }
  326.  
  327.         l = List;
  328.  
  329.         cout << "Не задовільно (0 - 49)\n";
  330.         cout << "Прізвище\t" << "Ім'я\t" << "По-батькові\t" << "Вік учня\t" << "Середній бал\n";
  331.  
  332.         while(l -> next != NULL){
  333.             l = l -> next;
  334.             if(l ->progress >= 0 && l ->progress < 50){
  335.                 cout << l->surname << "\t" << l->name << "\t" << l->patronymic << "\t" << l->age << "\t" << l->progress <<"\n";
  336.             }
  337.         }
  338.  
  339.     }else{
  340.         cout << "Порожньо!\n";
  341.     }
  342. }
  343.  
  344. void Delete(student* List){  //удаление студента
  345.     string name;
  346.     student* temp=List;
  347.     student* last=List;
  348.     bool flag=false;
  349.  
  350.     cout << "Вкажіть прізвище студентів, яких бажаєте видалити: ";
  351.     cin >> name;
  352.  
  353.     while(last!=NULL){
  354.         if(last->surname==name){
  355.             while((temp->next!=last)&&(temp!=last))
  356.                 temp=temp->next;
  357.             if(temp==last){
  358.                 List=last->next;
  359.                 delete &List;
  360.                 }
  361.             else{
  362.                 temp->next=last->next;
  363.                 delete &last;
  364.             }
  365.  
  366.             flag=true;
  367.  
  368.         }
  369.         last=last->next;
  370.     }
  371.  
  372.     if(flag==false)
  373.         cout << "Жодного студента з такими даними не знайдено!" << endl;
  374.  
  375.     else cout << "Студентів видалено!" << endl;
  376. }
  377.  
  378.  
  379.  
  380. int main(){
  381.     SetConsoleCP(1251);
  382.     SetConsoleOutputCP(1251);
  383.  
  384.     student* first = new student;
  385.     string fam;
  386.     int flag;
  387. while(true){
  388.         cout<<endl;
  389.         cout << "Меню: " << endl;
  390.         cout << "1.Перегляд усієї групи" << endl;
  391.         cout << "2.У початок" << endl;
  392.         cout << "3.У кінець" << endl;
  393.         cout << "4.Після учня з прізвищем" << endl;
  394.         cout << "5.Пошук за прізвищем" << endl;
  395.         cout << "6.Друк за балами" << endl;
  396.         cout << "7.Видалення за прізвищем" << endl;
  397.         cout << "8 Вихід\n";
  398.         cin>>flag;
  399.     switch(flag){
  400.         case 1:
  401.             print(first);
  402.         break;
  403.  
  404.         case 2:
  405.             Add_Beg(first);
  406.         break;
  407.  
  408.         case 3:
  409.             addLast(first);
  410.         break;
  411.  
  412.         case 4:
  413.             addAfter(first);
  414.         break;
  415.  
  416.         case 5:
  417.             Search(first);
  418.         break;
  419.  
  420.         case 6:
  421.             progress(first);
  422.         break;
  423.  
  424.         case 7:
  425.         Delete(first);
  426.         break;
  427.         case 8:
  428.             return 0;
  429.  
  430.         default: cout<<"1-8!";
  431.                     break;
  432.     }
  433. }
  434.  
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement