Advertisement
namemkazaza

Tanosing_Final

Jan 24th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <Windows.h>
  4. #include <string>
  5. #include <clocale>
  6. using namespace std;
  7. int iq_c = 0;
  8. int mid_iq = 0;
  9. const string names[] = { "Верос Нерети", "Трерас Дрес", "Тирер Белвайн", "Арон Андарен", "Эд Теман", "Энар Релет", "Фелен Марион", "Лларар Берелот", "Рерон Ринит", "Мавон Дреним" };
  10.  
  11. class student{
  12. public:
  13.     string FIO = names[rand() % 10];
  14.     int iq = 0;
  15.     student(){ iq = rand() % 100; }
  16.     student(int i){ iq = i; }
  17.     student(string s, int i){ FIO = s; iq = i; }
  18.     student(string s){ FIO = s; iq = rand() % 100; }
  19.     void show(){
  20.         cout << "\n" << FIO << " : " << iq;
  21.     }
  22. };
  23.  
  24. struct element{
  25.     student* data;
  26.     element* next;
  27. };
  28.  
  29. class group{
  30. private:
  31.     element *list, *cur, *temp;
  32.     int current = 0;
  33.  
  34. public:
  35.     void add(int n){
  36.         for (int i = 0; i < n; i++) add();
  37.     }
  38.     void add(){
  39.         temp = new element();
  40.         temp->data = new student();
  41.         temp->next = list->next;
  42.         list->next = temp;
  43.     }
  44.     void show(){
  45.         temp = list->next;
  46.         while (temp){
  47.             temp->data->show();
  48.             temp = temp->next;
  49.         }
  50.     }
  51.     void show(int n)
  52.     {
  53.         if (n > count()||n<=0)
  54.         {
  55.             cout << "\n\n >>> !!! tu ma4 h04esh !!! ERROR!!! <<< \n";
  56.         }
  57.         else
  58.         {
  59.             current = n;
  60.             temp = list->next;
  61.             int i = 1;
  62.             while (i != n)
  63.             {
  64.                 i++;
  65.                 temp = temp->next;
  66.             }
  67.             temp->data->show();
  68.         }
  69.     }
  70.     int count()
  71.     {
  72.         int i = 0;
  73.         temp = list->next;
  74.         while (temp){
  75.             i++;
  76.             temp = temp->next;
  77.         }
  78.         return i;
  79.     }
  80.     void del(){
  81.         if (list->next){
  82.             temp = list->next;
  83.             list->next = list->next->next;
  84.             delete temp;
  85.         }
  86.     }
  87.     void del(int n){
  88.         for (int i = 0; i < n; i++) del();
  89.     }
  90.     void middle_iq(){
  91.         float s = 0;
  92.         float k = 0;
  93.         temp = list->next;
  94.         while (temp){
  95.             s += temp->data->iq;
  96.             k++;
  97.             temp = temp->next->next;
  98.         }
  99.         show();
  100.         cout << endl;
  101.         cout << "Middle iq : " << s / k << endl;
  102.     }
  103.     void more_iq(int n){
  104.         int c = 0;
  105.         temp = list->next;
  106.         while (temp){
  107.             if (temp->data->iq > n) c++;
  108.             temp = temp->next->next;
  109.         }
  110.         show();
  111.         cout << endl;
  112.         cout << "Количество студентов с iq выше заданного : " << c;
  113.     }
  114.     void next()
  115.     {
  116.         current++;
  117.         show(current);
  118.     }
  119.     void prev()
  120.     {
  121.         current--;
  122.         show(current);
  123.     }
  124.     void del_cert(int n)
  125.     {
  126.         if (n > count() || n <= 0)
  127.         {
  128.             cout << "\n\n >>> !!! tu ma4 h04esh !!! ERROR!!! <<< \n";
  129.         }
  130.         else
  131.         {
  132.             temp = list->next;
  133.             int i = 1;
  134.             while (i != n)
  135.             {
  136.                 i++;
  137.                 temp = temp->next;
  138.             }
  139.         }
  140.         del();
  141.     }
  142.     void add_n_element(int n){
  143.         if (n <= 0 || n > count() + 1) {
  144.             cout << "\n !!! tu ma4 h04esh !!! EPPOP !!! <<< \n";
  145.         }
  146.         else if (n == 1) {
  147.             add();
  148.         }
  149.         else {
  150.             current = n;
  151.             int i = 1;
  152.             cur = list->next;
  153.             while (i < n - 1) {
  154.                 i++;
  155.                 cur = cur->next;
  156.             }
  157.             temp = new element();
  158.             string FIO = names[rand() % 10];
  159.             temp->data = new student(FIO);
  160.             temp->next = cur->next;
  161.             cur->next = temp;
  162.         }
  163.         show();
  164.     }
  165.     group(){
  166.         list = new element();
  167.         list->data = NULL;
  168.         list->next = NULL;
  169.     }
  170.     group(int n){
  171.         list = NULL;
  172.         add(n);
  173.     }
  174.     void tanosing(){
  175.         while (list) del();
  176.     }
  177.     ~group(){
  178.         while (list) del();
  179.     }
  180. };
  181.  
  182.  
  183. int main(){
  184.     setlocale(LC_CTYPE, "Russian");
  185.     group* G21 = new group();
  186.     int choose;
  187.     int n;
  188.     do{
  189.  
  190.         cout << "1-add  2-add(n)  3-del  4-del(n)  5-show  6-shel4ok  7-student number  8-mid_iq  9-more_iq(n)  10-del(x)  0-exit\n";
  191.         cout << "11 show(n) 12-prev 13-next 14-del_cert 15-add_n_element \n";
  192.         cout << "? >> ";
  193.         cin >> choose;
  194.         system("CLS");
  195.         switch (choose){
  196.         case 1: G21->add(); G21->show(); break;
  197.         case 2:  cin >> n; G21->add(n); G21->show(); break;
  198.         case 3: G21->del(); G21->show(); break;
  199.         case 4:  cin >> n; G21->del(n); G21->show(); break;
  200.         case 5: G21->show(); break;
  201.         case 6: G21->tanosing(); break;
  202.         case 7: cout << "Количество студентов: "; cout << G21->count(); break;
  203.         case 8: G21->middle_iq(); break;
  204.         case 9: cin >> n; G21->more_iq(n); break;
  205.         case 11: cin >> n; G21->show(n); break;
  206.         case 12: G21->prev(); break;
  207.         case 13: G21->next(); break;
  208.         case 14: cin >> n; G21->del_cert(n); G21->show(); break;
  209.         case 15: cin >> n; G21->add_n_element(n); break;
  210.         }
  211.  
  212.         cout << "\n================================\n";
  213.     } while (choose != 0);
  214.     cout << "\n\n\n\n";
  215.     system("pause");
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement