EternalHaru

TempCodeOfFIFO

Mar 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<string>
  4. #include<string.h>
  5. using namespace std;
  6.  
  7.  
  8. struct Student
  9. {
  10.     int num;
  11.     string fam;
  12.     string nam;
  13.     int stdn;
  14.     string dbd;
  15.     string phone;
  16.     int marks[8];
  17.     Student* next;
  18.  
  19. };
  20.  
  21.  
  22. struct Group
  23. {
  24.     int number;
  25.     int size;
  26.     static Group* head;
  27.     static Group* last;
  28.     static int grcount;
  29.     Student* adr;
  30.     Student* adr_last;
  31.     Group* next;
  32.     Group(int N)
  33.     {
  34.         number = N;
  35.         size = 0;
  36.         head = 0;
  37.         last = 0;
  38.         adr = 0;
  39.         adr_last = 0;
  40.     }
  41.     void add_group(int N);
  42.     void del_group(int N);
  43.     void print_group();
  44.     void search_group(int N);
  45. };
  46.  
  47. Group* Group::head;
  48. Group* Group::last;
  49. int Group::grcount;
  50.  
  51. void Group::add_group(int N)
  52. {
  53.     bool k = false;
  54.     Group* temp = head;
  55.     while (temp)
  56.     {
  57.         if (temp->number == N)
  58.         {
  59.             cout << "Такая группа уже существует!";
  60.             k = true;
  61.         }
  62.         temp = temp->next;
  63.     }
  64.     if (!k)
  65.     {
  66.         temp = new Group(N);
  67.         if (last)
  68.         {
  69.             last->next = temp;
  70.             last = temp;
  71.             temp->next = 0;
  72.         }
  73.         else
  74.         {
  75.             head = last = temp;
  76.         }
  77.         grcount++;
  78.         cout << "Новая группа номер " << N << " создана!\n";
  79.     }
  80.     cout << "Нажмите любую кнопку для продолжения!\n";
  81.     _getch();
  82.     system("cls");
  83. }
  84.  
  85.  
  86. void Group::del_group(int N)
  87. {
  88.     Group* temp = head;
  89.     Group* prev_temp = 0;
  90.     while (temp)
  91.     {
  92.         if (temp->number == N)
  93.         {
  94.             Student* stud_temp = temp->adr;
  95.             Student* stud_temp2 = 0;
  96.             while (stud_temp)
  97.             {
  98.                 stud_temp2 = stud_temp->next;
  99.                 delete stud_temp;
  100.                 stud_temp = stud_temp2;
  101.             }
  102.             if ((temp->next) && (prev_temp))
  103.             {
  104.                 prev_temp->next = temp->next;
  105.             }
  106.             if ((temp->next == 0) && (temp != head))
  107.             {
  108.                 last = prev_temp;
  109.                 last->next = 0;
  110.             }
  111.             if ((temp == head) && (temp->next))
  112.             {
  113.                 head = temp->next;
  114.             }
  115.             if ((temp == head) && (temp == last))
  116.             {
  117.                 head = last = 0;
  118.             }
  119.             delete stud_temp;
  120.             grcount--;
  121.             cout << "Группа " << N << " удалена!\n";
  122.             break;
  123.         }
  124.         else if (temp->next == 0)
  125.         {
  126.             cout << "Данной группы не существуеи!\n";
  127.         }
  128.         prev_temp = temp;
  129.         temp = temp->next;
  130.     }
  131.     cout << "Чтобы продолжить нажмите любую кнопку!\n";
  132.     _getch();
  133.     system("cls");
  134. }
  135.  
  136.  
  137. void Group::print_group()
  138.     {
  139.         Group* temp = head;
  140.         cout << "Список групп: \n\n";
  141.         while (temp)
  142.         {
  143.             cout << "________________________________________________\n";
  144.             cout << "Номер группы: " << temp->number << " \n";
  145.             cout << "Количество человек в группе: " << temp->size << " \n";
  146.             cout << "________________________________________________\n";
  147.             temp = temp->next;
  148.         }
  149.         cout << "Конец списка!\n";
  150.         cout << "Нажмите любую кнопку для продолжения!\n";
  151.         _getch();
  152.         system("cls");
  153.     }
  154.  
  155.  
  156. void Group::search_group(int N)
  157. {
  158.     Group* temp = head;
  159.     while (temp)
  160.     {
  161.         if (temp->number == N)
  162.         {
  163.             cout << "Группа существует!\n";
  164.             break;
  165.         }
  166.         else if (temp->next == 0)
  167.         {
  168.             cout << "Группа не существует!\n";
  169.         }
  170.         temp = temp->next;
  171.     }
  172.     cout << "Чтобы продолжить нажмите любую кнопку!\n";
  173.     _getch();
  174.     system("cls");
  175. }
Advertisement
Add Comment
Please, Sign In to add comment