Advertisement
Savelyev_Vyacheslav

Practika_24.01.2021 + drugoi kod smes

Jan 22nd, 2021
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream> // chtenie faila
  4. #include <stdlib.h>     //for using the function sleep
  5. #include <windows.h> // для Win32 систем
  6. #include <clocale>
  7. using namespace std;
  8.  
  9.  
  10. class Otsenki {
  11.         string fizika;
  12.         string istoriya;
  13.         string informatika;
  14.     friend class List;
  15.         friend class Node;
  16. };
  17. class Node
  18. {
  19.     string FirstName;
  20.     string LastName;
  21.     string N_student;
  22.     Otsenki *OtsenkiPtr = new Otsenki();
  23.     class Node *ptr;
  24.     friend class List;
  25. };
  26.  
  27.  
  28.  
  29. class List
  30. {
  31.     Node *head;
  32.     int count = 0;
  33.     Node* Prev(Node *); // Переход к предыдущему узлу (не интерфейсный метод)
  34. public:
  35.     List() { head = NULL; } // Инициализация списка
  36.     int getCount() { return count; } // Получение количества узлов списка
  37.     bool isEmpty() { return head == NULL; }  // Проверка, пуст ли список
  38.     string getValue(Node* p) { return p->N_student; } // Получение значения  узла списка
  39.     string getValue2(Node* p) { return p->FirstName; } // Получение значения узла списка
  40.     string getValue3(Node* p) { return p->LastName; } // Получение значения 2го узла списка
  41.     string getValue4(Node* p) {  return p->OtsenkiPtr->fizika; }
  42.     string getValue5(Node* p) {  return p->OtsenkiPtr->istoriya; }
  43.     string getValue6(Node* p) { return p->OtsenkiPtr->informatika; }
  44.  
  45.     Node* Add(string, string, string, string, string, string, Node*); // Добавление узла списка
  46.     Node* ChekValidALL(string, string, string, string, string, string); // Добавление узла списка
  47.     void setValue(Node *p, int val) { p->FirstName = val; } // Установка значения узла списка
  48.     Node* getFirst() { return head; } // Получение корневого узла списка
  49.     Node* getLast();            // Получение последнего узла списка
  50.     void Clear();               // Очистка списка
  51.     Node* Next(Node *);         // Переход к следующему узлу
  52.    
  53.     Node* Delete(Node*);        // Удаление узла списка
  54.     void Print();               // Вывод значений узлов списка
  55.     void Swap(Node*, Node*);    // Взаимообмен двух узлов
  56.     void String_total_X();              // поиск X
  57.     int ValidText(string);
  58.     int ValidChislo(string);
  59.     string reedOfFile(string);
  60.     void Delete_ALL();
  61.     Node* Print_By_value();
  62.     int CountElement();
  63.  
  64.     Node* Nomer_s_kontsa_del(); // удален середина по номеру
  65.     Node* Zamena(); // замена
  66.     Node* Zamena_ptr(); // замена по указателю
  67.     Node* HeadToEnd(); // замена местами по указателю первый назад последний вперед
  68.     Node* FILO(); // первый назад
  69.     Node* LIFO(); // последний вперед
  70.     void StekOperation(); // DZ po AIP
  71.  
  72.     Node* Dobav_n_last(string); // добавить в конец
  73.     Node* Dobav_pre_last(); // добавить перед конец
  74.     Node* Dobav_head(); // добавить перед конец
  75.     Node* Dobav_head_next(); // добавить перед конец
  76.  
  77.     Node* head_del(); // udalit golovu
  78.     Node* head_next_del(); // udalit 2 s golovu
  79.     Node* Delete_end(); // удаляет конец
  80.     Node* Delete_prev_end(); // удален предпоследний
  81.  
  82.     Node* Del_By_value(); // udalit po znacheniu
  83.     void WriteFromProgToTxt(string);
  84.     void ReedOfTxtToProg(string);
  85.    
  86. };
  87.  
  88. Node* List::ChekValidALL(string num1, string num2, string num3, string num4, string num5, string num6)
  89. {  
  90.     if (!ValidChislo(num1)) { cout << " 1-N_student "; return NULL; }
  91.     if (!ValidText(num2)){ cout << " 2-FirstName "; return NULL; }
  92.     if (!ValidText(num3)) { cout << " 3-LastName "; return NULL; }
  93.     if (!ValidChislo(num4))  { cout << " 4-fizika "; return NULL; }
  94.     if (!ValidChislo(num5))  { cout << " 5-istoriya "; return NULL; }
  95.     if (!ValidChislo(num6)) { cout << " 6-informatika "; return NULL; }
  96. }
  97.  
  98. Node* List::Add( string num1, string num2, string num3, string num4, string num5, string num6, Node* node = NULL)
  99. {
  100.     ChekValidALL(num1,num2, num3,  num4, num5, num6);
  101.     Node *elem = new Node();
  102.      elem->N_student = num1;
  103.      elem->FirstName = num2;
  104.      elem->LastName = num3;
  105.      elem->OtsenkiPtr->fizika = num4;
  106.      elem->OtsenkiPtr->istoriya = num5;
  107.      elem->OtsenkiPtr->informatika = num6;
  108.    
  109.     count++;
  110.     if (node == NULL) // Добавление нового корня
  111.     {
  112.         if (head == NULL) {
  113.             elem->ptr = NULL;
  114.             head = elem;
  115.         }
  116.         else {
  117.             elem->ptr = head;
  118.             head = elem;
  119.         }
  120.         return elem;
  121.     }
  122.     elem->ptr = node->ptr; // Добавление узла после текущего
  123.     node->ptr = elem;
  124.     return elem;
  125. }
  126.  
  127. Node* List::Delete(Node* node)
  128. {
  129.     if (node == NULL) { return NULL; } // В списке нет узлов
  130.     count--;
  131.     if (node == head)   // Удаление корневого узла
  132.     {
  133.         head = node->ptr;
  134.         delete node;
  135.         return head;
  136.     }
  137.     Node* prev = Prev(node); // Удаление промежуточного узла
  138.     prev->ptr = node->ptr;
  139.     delete node;
  140.     return prev;
  141. }
  142. ////////////////
  143. Node* List::Delete_end()
  144. {
  145.     Node *temp = NULL;
  146.     Node *head2 = head;
  147.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  148.     count--;
  149.     while (head2->ptr != NULL) {  // перемотка на последние указатели
  150.         temp = head2;
  151.         head2 = head2->ptr;
  152.     }
  153.     if (temp) {
  154.         //<udalenie poslednego>
  155.         temp->ptr = NULL;
  156.         delete head2;
  157.         //< /udalenie poslednego>
  158.     }
  159.     cout << temp->FirstName << " - " << temp << " - " << temp->ptr << endl;
  160. }
  161. ////////////////
  162. ////////////////
  163. Node* List::Dobav_head()
  164. {
  165.     Node *temp = NULL;
  166.     Node *head2 = head;
  167.     //Node *uzel = head;
  168.     //cout << "add to head: ";
  169.     string z1, z2, z3, z4, z5, z6;
  170.     cin >> z1 >> z2 >> z3 >> z4 >> z5 >> z6;
  171.     ChekValidALL(z1, z2, z3, z4, z5, z6);
  172.     //<opation>
  173.     Node *elem = new Node();
  174.     elem->N_student = z1;
  175.     elem->FirstName = z2;
  176.     elem->LastName = z3;
  177.     elem->OtsenkiPtr->fizika = z4;
  178.     elem->OtsenkiPtr->istoriya = z5;
  179.     elem->OtsenkiPtr->informatika = z6;
  180.     elem->ptr = head2;
  181.     head = elem;
  182.     //</opation>
  183.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  184.     count++;
  185. }
  186. ////////////////
  187. ////////////////
  188. Node* List::Dobav_head_next()
  189. {
  190.     Node *t1 = NULL;
  191.     Node *t2 = head;
  192.     t1 = head;
  193.     t2 = t2->ptr;
  194.     //<operation>
  195.     Node *elem2 = new Node();
  196.     elem2->FirstName = "88";
  197.     t1->ptr = elem2;
  198.     elem2->ptr = t2;
  199.     //<operation>
  200.     if (t2 == NULL) { return NULL; } // В списке нет узлов
  201.     count++;
  202. }
  203. ////////////////
  204. ////////////////
  205. Node* List::Dobav_n_last(string value = "88")
  206. {
  207.     Node *temp = NULL;
  208.     Node *head2 = head;
  209.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  210.     count++;
  211.     while (head2->ptr != NULL) {
  212.         temp = head2;
  213.         head2 = head2->ptr;
  214.     }
  215.     // <operation>
  216.     Node *elem2 = new Node();
  217.     elem2->FirstName = value;
  218.     elem2->ptr = NULL;
  219.     head2->ptr = elem2;
  220.     // </operation>
  221.     cout << head2->FirstName << " test " << head2 << " test " << endl;
  222.     cout << head2->ptr->FirstName << " test " << head2->ptr << " test " << endl;
  223. }
  224. ////////////////
  225. /////////////////
  226. Node* List::Dobav_pre_last()
  227. {
  228.     Node *temp = NULL;
  229.     Node *t = head;
  230.     Node *head2 = head;
  231.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  232.     count--;
  233.     while (head2->ptr != NULL) {
  234.         head2 = head2->ptr;
  235.         t = t->ptr;
  236.         if (t->ptr->ptr == NULL) {
  237.             temp = t->ptr;
  238.             cout << t->FirstName << " test2 " << t << " test2 " << endl;
  239.             cout << temp->FirstName << " test2 " << temp->ptr << " test2 " << endl;
  240.             //<operation>
  241.             Node *elem2 = new Node();
  242.             elem2->FirstName = "88";
  243.             t->ptr = elem2;
  244.             elem2->ptr = temp;
  245.             //</operation>
  246.             return NULL;
  247.         }
  248.     }
  249. }
  250. ////////////////
  251. ////////////////
  252. Node* List::Delete_prev_end()
  253. {
  254.     count++;
  255.     Node *temp = NULL;
  256.     Node *head2 = head;
  257.     Node *t = head;
  258.     Node *t2 = head;
  259.     Node *t3 = head;
  260.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  261.     if (head2->ptr == NULL) { return NULL; } // В списке нет узлов по условию
  262.     if (head2->ptr->ptr == NULL) { return NULL; } // В списке нет узлов
  263.     count--;
  264.     int j = 0;
  265.     cout << head2->FirstName << " - " << head2 << " - " << endl;
  266.     while (head2->ptr != NULL) {
  267.         j++;
  268.         head2 = head2->ptr;
  269.         temp = head2;
  270.         t = temp->ptr;
  271.         t3 = t->ptr;
  272.         cout << temp->FirstName << " - " << temp << " - " << endl;
  273.         cout << t->FirstName << " - " << t << " - " << endl;
  274.         cout << t3->FirstName << " - " << t3 << " - " << endl;
  275.  
  276.         if (head2->ptr->ptr->ptr == NULL) {
  277.             //// <operation>
  278.             temp->ptr = t3; delete t;
  279.             //// </operation>
  280.             cout << temp->FirstName << " Проверка " << temp << " - " << endl;
  281.             cout << temp->ptr->FirstName << " Проверка " << temp->ptr << " - " << endl;
  282.             cout << "temp->ptr->ptr->FirstName" << " Проверка " << temp->ptr->ptr << " - " << endl;
  283.             cout << "t3->ptr->FirstName" << " - " << t3->ptr << " - " << endl;
  284.             return NULL;
  285.         }
  286.     }
  287. }
  288. ///////////////////
  289. ////////////////
  290. Node* List::Nomer_s_kontsa_del()
  291. {
  292.     count++;
  293.     Node *temp = NULL;
  294.     Node *head2 = head;
  295.     Node *t = head;
  296.     Node *t2 = head;
  297.     Node *t3 = head;
  298.     Node *t4 = head;
  299.     int nomer_s_kontsa = 4;
  300.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  301.     count--;
  302.     int i = 0;
  303.     int vsego;
  304.     while (t2->ptr != NULL) {
  305.         t2 = t2->ptr;
  306.         i++;
  307.         vsego = i;
  308.     }
  309.     // proverka na sootvetstvie spisku
  310.     if ((vsego + 1) <= nomer_s_kontsa) { cout << " Nomer ne sootvetstvuet spisku|" << nomer_s_kontsa << "- этого номера нет " << endl;   return NULL; }
  311.  
  312.     cout << " vsego  " << (vsego + 1) << " - " << endl;
  313.     int j = 0;
  314.  
  315.     while (head2->ptr != NULL) {
  316.         if (j == (vsego - nomer_s_kontsa)) {
  317.             temp = head2;
  318.             t = temp->ptr;
  319.             t3 = t->ptr;
  320.             //// <perenos ukazatelya udalenie>
  321.             temp->ptr = t3; delete t;
  322.             //// </ perenos ukazatelya udalenie>
  323.             cout << j << " Проверка " << temp << " - " << endl;
  324.             head2 = head2->ptr;
  325.         }
  326.         else {
  327.             head2 = head2->ptr;
  328.         }
  329.         j++;
  330.     }
  331. }
  332. ///////////////////
  333. int List::CountElement()
  334. {
  335.     Node *t = head;
  336.  
  337.     int i = 0;
  338.     int vsego;
  339.     while (t->ptr != NULL) {
  340.         t = t->ptr;
  341.         i++;
  342.         vsego = i;
  343.     }
  344.     return vsego;
  345. }
  346. ////////////////
  347. Node* List::Del_By_value()
  348. {
  349.     Node *temp = NULL;
  350.     Node *head2 = head;
  351.     Node *t = head;
  352.     Node *t2 = head;
  353.     Node *t3 = head;
  354.     Node *t4 = head;
  355.     Node *tail = head;
  356.  
  357.     string value_del;
  358.     cin >> value_del;
  359.     if (head2 == NULL) { cout << "pusto "; return NULL; } // В списке нет узлов
  360.     if (head2->ptr == NULL) { cout << "udali vse ";  return NULL; } // В списке 1 узел
  361.     while (tail->ptr != NULL) {
  362.         tail = tail->ptr;
  363.         //cout << " Проверка222 " << tail->FirstName << " - " << endl;
  364.     }
  365.    
  366.     if (head2->ptr->ptr == NULL) {
  367.         if (head2->LastName == value_del) {  // kluch v golove
  368.             head_del(); //cout << "test ";
  369.         }
  370.         if (tail->LastName == value_del) { // kluch v hvoste
  371.             Delete_end();
  372.         }
  373.     return NULL; } // В списке 2 узла
  374.     else {
  375.     int j = 0;
  376.     while (head2 != NULL) {
  377.         temp = head2;
  378.         t = temp->ptr;
  379.         if (t->LastName == value_del) {
  380.            
  381.             t3 = t->ptr;
  382.             //// <operation>
  383.             temp->ptr = t3; delete t;
  384.             //// </operation>
  385.             //cout << j << " Проверка " << temp->FirstName << " - " << endl;
  386.             //cout << j << " Проверка " << t->FirstName << " - " << endl;
  387.             //cout << j << " Проверка " << t3->FirstName << " - " << endl;
  388.             break;
  389.         }
  390.         head2 = head2->ptr;
  391.         j++;
  392.     }
  393.   }
  394. }
  395. ///////////////////
  396. ////////////////
  397. Node* List::Print_By_value()
  398. {
  399.     Node *head2 = head;
  400.  
  401.     string value_del;
  402.     cout << " Vvedite FAMELIU dlya poiska > ";
  403.     cin >> value_del;
  404.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  405.    
  406.     while (head2 != NULL) {
  407.  
  408.         if (head2->LastName == value_del) {
  409.             //typ[0];
  410.             cout << " Nomer > " << head2->N_student << " < " << head2->FirstName+' '<< head2->LastName + ' ' <<  head2->OtsenkiPtr->fizika + ' ' << head2->OtsenkiPtr->istoriya + ' ' << head2->OtsenkiPtr->informatika + ' ' << endl;
  411.         }
  412.         head2 = head2->ptr;
  413.     }
  414. }
  415. ///////////////////
  416. ////////////////
  417. Node* List::head_next_del()
  418. {
  419.     Node *t1 = NULL;
  420.     Node *head2 = head;
  421.     Node *t2 = head;
  422.     Node *t3 = head;
  423.     t1 = head;
  424.     t2 = t1->ptr;
  425.     t3 = t2->ptr;
  426.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  427.     // <ukazateli dlya operatsii>
  428.     cout << t1->FirstName << " - " << t1 << " - " << endl;
  429.     cout << t2->FirstName << " - " << t2 << " - " << endl;
  430.     cout << t3->FirstName << " - " << t3 << " - " << endl;
  431.     // </ukazateli dlya operatsii>
  432.     // <operation>
  433.     t1->ptr = t3;
  434.     t2->ptr = NULL;
  435.     delete t2;
  436.     // </operation>
  437.     // <proverka>
  438.     cout << head2->FirstName << " - " << head2 << " - " << endl;
  439.     cout << head2->ptr->FirstName << " - " << head2->ptr << " - " << endl;
  440.     cout << head2->ptr->ptr->FirstName << " - " << head2->ptr->ptr << " - " << endl;
  441.     // </proverka>
  442. }
  443. ////////////////
  444. ////////////////
  445. Node* List::head_del()
  446. {
  447.     Node *h = head;
  448.     Node *t = head;
  449.     if (h == NULL) { return NULL; } // В списке нет узлов
  450.     //<operation>
  451.     head = h->ptr;
  452.     t = NULL;
  453.     delete t;
  454.     //</operation>
  455. }
  456. ////////////////
  457. ////////////////
  458. Node* List::Zamena_ptr()
  459. {
  460.     Node *temp = NULL;
  461.     Node *head2 = head;
  462.     Node *t = head;
  463.     Node *t2 = head;
  464.     Node *t3 = head;
  465.     Node *t4 = head;
  466.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  467.     int i = 0;
  468.     int n_zameny = 3;
  469.     while (head2->ptr != NULL) {
  470.         t2 = head2;
  471.         head2 = head2->ptr;
  472.         if (i == (n_zameny - 2)) {
  473.             temp = head2;
  474.             cout << " Замена " << n_zameny << endl;
  475.             head2 = head2->ptr;
  476.             t3 = temp->ptr;
  477.             // <vivod nuzhnih peremennih>
  478.             cout << t->FirstName << " - " << t << " - " << endl;
  479.             cout << t2->FirstName << " - " << t2 << " - " << endl;
  480.             cout << temp->FirstName << " - " << temp << " - " << endl;
  481.             cout << t3->FirstName << " - " << t3 << " - " << endl;
  482.             // </vivod nuzhnih peremennih>
  483.             // </ operation>
  484.             t4 = t4->ptr;  // второй
  485.             t2->ptr = t;  // связь перед t. t был первым
  486.             t->ptr = t3;  // связь после t. t был первым
  487.             head = temp; // новый хэд темп выбран по номеру n_zameny
  488.             temp->ptr = t4; // указатель на второй
  489.             // < operation>
  490.             // < proverka>
  491.             cout << head->FirstName << " 1 " << head << " - " << endl;
  492.             cout << t2->FirstName << " n " << t2 << " - " << endl;
  493.             cout << t2->ptr->FirstName << " n+1 " << t2->ptr << " - " << endl;
  494.             cout << t3->FirstName << " n+2 " << t3 << " - " << endl;
  495.             // < proverka>
  496.         }
  497.         i++;
  498.     }
  499. }
  500. ///////////////////
  501. ////////////////
  502. Node* List::HeadToEnd()
  503. {
  504.     Node *temp = NULL;
  505.     Node *head2 = head;
  506.     Node *t = head;
  507.     Node *t2 = head;
  508.     Node *t3 = head;
  509.     Node *t4 = head;
  510.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  511.     int i = 0;
  512.     int n_zameny = 10;
  513.     while (head2->ptr != NULL) {
  514.         head2 = head2->ptr;
  515.         t2 = head2;
  516.         if (t2->ptr->ptr->ptr == NULL) {
  517.             t2 = head2;
  518.             temp = t2->ptr;
  519.             cout << " Замена " << n_zameny << endl;
  520.             //head2 = head2->ptr;
  521.             t3 = temp->ptr;
  522.             // <vivod nuzhnih peremennih>
  523.             cout << t->FirstName << " - " << t << " - " << endl;
  524.             cout << t2->FirstName << " - " << t2 << " - " << endl;
  525.             cout << temp->FirstName << " - " << temp << " - " << endl;
  526.             cout << t3->FirstName << " - " << t3 << " - " << endl;
  527.             // </vivod nuzhnih peremennih>
  528.             // </ podstanovka>
  529.             t4 = t4->ptr;
  530.             head = t3;
  531.             t3->ptr = t4;
  532.             temp->ptr = t; t->ptr = NULL;
  533.             // < podstanovka>
  534.             return NULL;
  535.         }
  536.         i++;
  537.     }
  538. }
  539. ///////////////////
  540. ////////////////
  541. Node* List::LIFO()
  542. {
  543.     Node *temp = NULL;
  544.     Node *head2 = head;
  545.     Node *t = head;
  546.     Node *tt = head;
  547.     Node *t2 = head;
  548.     Node *t3 = head;
  549.     Node *t4 = head;
  550.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  551.     int i = 0;
  552.     int n_zameny = 10;
  553.  
  554.     while (head2->ptr != NULL) {
  555.         t2 = head2;
  556.         t4 = t2->ptr;
  557.  
  558.         if (t2->ptr->ptr == NULL) {
  559.             // <vivod nuzhnih peremennih>
  560.             cout << t2->FirstName << " -- " << t2 << " - " << endl;
  561.             cout << t4->FirstName << " -- " << t4 << " - " << endl;
  562.             // </vivod nuzhnih peremennih>
  563.             // </ podstanovka>
  564.             head = t4;
  565.             t4->ptr = t3;
  566.             t2->ptr = NULL;
  567.             // < podstanovka>
  568.             return NULL;
  569.         }
  570.         head2 = head2->ptr; t2 = t2->ptr;
  571.         i++;
  572.     }
  573.  
  574. }
  575. ///////////////////
  576. ////////////////
  577. Node* List::FILO()
  578. {
  579.     Node *temp = NULL;
  580.     Node *head2 = head;
  581.     Node *t = head;
  582.     Node *tt = head;
  583.     Node *t2 = head;
  584.     Node *t3 = head;
  585.     Node *t4 = head;
  586.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  587.     int i = 0;
  588.     while (head2->ptr != NULL) {
  589.         head2 = head2->ptr;
  590.         t2 = head2;
  591.         if (t2->ptr == NULL) {
  592.             t2 = head2;
  593.             temp = t2->ptr;
  594.             // <vivod nuzhnih peremennih>
  595.             //cout << t->FirstName << " -- " << t << " - " << endl;
  596.             //cout << t2->FirstName << " -- " << t2 << " - " << endl;
  597.             // </vivod nuzhnih peremennih>
  598.             // </ podstanovka>
  599.             t4 = t4->ptr;
  600.             head = t4;
  601.             t2->ptr = t;
  602.             t->ptr = NULL;
  603.             // < podstanovka>
  604.             return NULL;
  605.         }
  606.         i++;
  607.     }
  608.  
  609. }
  610. ///////////////////
  611. ////////////////
  612. Node* List::Zamena()
  613. {
  614.     Node *temp = NULL;
  615.     Node *head2 = head;
  616.     Node *t = head;
  617.     if (head2 == NULL) { return NULL; } // В списке нет узлов
  618.     int i = 0;
  619.     int n_zameny;
  620.     cout << " Введи номер замены " << endl;
  621.     cin >> n_zameny;
  622.  
  623.     while (head2->ptr != NULL) {
  624.         if (i == (n_zameny - 1)) {
  625.             temp = head2;
  626.             cout << " Замена " << n_zameny << endl;
  627.         }
  628.         head2 = head2->ptr;
  629.         cout << i << " - " << t << " - " << endl;
  630.         cout << i << " - " << temp << " - " << endl;
  631.         cout << i << " - " << head2->ptr << " - " << endl;
  632.         i++;
  633.     }
  634.     if (temp) {
  635.         string zamen1;
  636.         zamen1 = temp->FirstName;
  637.         temp->FirstName = t->FirstName; // вставляем значение первого в выбранный
  638.         t->FirstName = zamen1; // вставляем в первый значение выбранного
  639.     }
  640. }
  641. ///////////////////
  642. ////////////////
  643. void List::StekOperation()
  644. {
  645.     while (true)
  646.     {
  647.         int opN;
  648.         cout << "Operation  Dobav_head-1 head_del-2 AddTail-3 DelTail-4 Print-5 Delet_ALL-6 ReedOf.Txt-7 \n";
  649.         cout << "           WriteFromProgToTxt-8 Print_By_value-9 Del_By_value-10 Exit-anyButton \n" ;
  650.         cin >> opN;
  651.         switch (opN) {
  652.         case 1:
  653.             cout << "Dobav_head\n"; Dobav_head();
  654.             break;
  655.         case 2:
  656.             cout << "head_del\n"; head_del();
  657.             break;
  658.         case 3:
  659.             cout << "AddTail\n"; Dobav_head(); FILO();
  660.             break;
  661.         case 4:
  662.             cout << "DelTail\n";  LIFO(); head_del();
  663.             break;
  664.         case 5:
  665.             cout << "Print\n"; Print();
  666.             break;
  667.         case 6:
  668.             cout << "Delete_ALL\n"; Delete_ALL();
  669.             break;
  670.         case 7:
  671.             cout << "ReedOfTxtToProg\n"; ReedOfTxtToProg("write.txt");
  672.             break;
  673.         case 8:
  674.             cout << "WriteFromProgToTxt\n"; WriteFromProgToTxt("write.txt");
  675.             break;
  676.         case 9:
  677.             cout << "Print_By_value\n"; Print_By_value();
  678.             break;
  679.         case 10:
  680.             cout << "Del_By_value\n"; Del_By_value();
  681.             break;
  682.         default:
  683.             cout << "Exit\n"; goto tryAgain;
  684.         }
  685.  
  686.     }
  687. tryAgain: // это лейбл
  688.     exit;
  689. }
  690. ///////////////////
  691.  
  692. void List::Print()
  693. {
  694.     if (isEmpty()) { cout << "Список пуст" << endl; return; }
  695.     Node *p = head;
  696.     do {
  697.         cout       << getValue(p)
  698.             << " " << getValue2(p)
  699.             << " " << getValue3(p)
  700.             << " " << getValue4(p)
  701.             << " " << getValue5(p)
  702.             << " " << getValue6(p)
  703.             << "\n";
  704.         p = Next(p);
  705.     } while (p != NULL);
  706.     cout << endl;
  707. }
  708.  
  709. void List::Clear()
  710. {
  711.     class Node *p = head;
  712.     if (p == NULL) return;
  713.     do {
  714.         Node *d = p;
  715.         p = Next(p);
  716.         delete d;
  717.     } while (p != NULL);
  718.     count = 0;
  719.     head = NULL;
  720. }
  721. void List::Delete_ALL()
  722. {
  723.     class Node *p = head;
  724.     if (p == NULL) return;
  725.     do {
  726.         Node *d = p;
  727.         p = p->ptr;
  728.         delete d;
  729.     } while (p != NULL);
  730.     count = 0;
  731.     head = NULL;
  732. }
  733.  
  734. Node* List::getLast()
  735. {
  736.     Node* p = head;
  737.     while (Next(p) != NULL)
  738.         p = Next(p);
  739.     return p;
  740. }
  741.  
  742. Node* List::Next(Node* node)
  743. {
  744.     if (isEmpty()) return NULL;
  745.     return node->ptr;
  746. }
  747.  
  748. Node* List::Prev(Node* node)
  749. {
  750.     if (isEmpty()) return NULL;
  751.     if (node == head) return NULL;
  752.     Node *p = head;
  753.     while (p->ptr != node)
  754.         p = p->ptr;
  755.     return p;
  756. }
  757.  
  758. void List::String_total_X() {
  759.  
  760.     string nameFile="students.txt";
  761.     string s = reedOfFile(nameFile);
  762.     //<podschet vseh simvolov v tekste>
  763.     ifstream inf(nameFile);
  764.     //cout << "start str";
  765.     int p = 0;
  766.     int i = 0;
  767.     while (inf)
  768.     {   i++;
  769.     cout << "\n<-----str#"<< i << "/---->" <<endl;
  770.         // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
  771.         string str;
  772.         getline(inf, str);
  773.         cout << str;
  774.  
  775.         p = 0;
  776.         if (str.find('X') != -1) {
  777.             //ValidText(s);
  778.             cout << "\n<----/str#" << i << "----->";
  779.             cout  << " Elementov v stroke - ";
  780.             for (auto c : str)
  781.                 if (c == 'X') {
  782.                     p++;
  783.                 }
  784.             cout << p << "\n";
  785.         }
  786.    
  787.     }
  788.  
  789.             p = 0;
  790.             if (s.find('X') != -1) {
  791. cout << "\n" << "\nVsego elementov v spiske ";
  792.                 for (auto c : s)
  793.                     if (c == 'X') {
  794.                         p++;
  795.                     }
  796.                 cout <<  p  << "\n\n";
  797.             }
  798.             std::system("pause");
  799.     //</podschet vseh simvolov v tekste>
  800.        
  801. }
  802. ////////////////
  803. int List::ValidText(string s) {
  804.         for (auto c : s)
  805.             if ((c <= '9')&&(c >= '0')) {
  806.                 cout << "Vi vveli cislo ne tuda";
  807.                 return 0;
  808.             }
  809.         return 1;
  810. }
  811. ////////////////
  812. ////////////////
  813. int List::ValidChislo(string s) {
  814.     for (auto c : s) {
  815.         if ((c <= 'z') && (c >= 'a')) {
  816.             cout << "Vi vveli text ne tuda"; return 0;
  817.         }
  818.         else if ((c <= 'Z') && (c >= 'A')) {
  819.             cout << "Vi vveli text  ne tuda"; return 0;
  820.         }
  821.         else if ((c <= 'Я') && (c >= 'А')) {
  822.             cout << "Vi vveli text  ne tuda"; return 0;
  823.         }
  824.         else if ((c <= 'я') && (c >= 'а')) {
  825.             cout << "Vi vveli text  ne tuda"; return 0;
  826.         }
  827.     }
  828.     return 1;
  829. }
  830. ////////////////
  831. void List::WriteFromProgToTxt(string path = "write.txt")
  832. {
  833.     //string path = "write.txt";
  834.     ofstream fout;
  835.     fout.open(path, ofstream::app);
  836.     if (!fout.is_open()) {
  837.         cout << "Ошибка открытия фаила"<< endl;
  838.         Sleep(5000);
  839.     }
  840.     else {
  841.             if (isEmpty()) { cout << "Список пуст" << endl; return; }
  842.             Node *p = head;
  843.             do {
  844.                fout << getValue(p)
  845.                     << " " << getValue2(p)
  846.                     << " " << getValue3(p)
  847.                     << " " << getValue4(p)
  848.                     << " " << getValue5(p)
  849.                     << " " << getValue6(p)
  850.                     << "\n";
  851.                 p = Next(p);
  852.             } while (p != NULL);
  853.     }
  854.     fout.close();
  855. }
  856. ///////////////////
  857. ////////////////
  858. void List::ReedOfTxtToProg(string nameFile="write.txt")
  859. {
  860.     ifstream inf(nameFile);
  861.     // Если мы не можем открыть файл для чтения его содержимого,
  862.     if (!inf)
  863.     {
  864.         // то выводим следующее сообщение об ошибке и выполняем функцию exit()
  865.         cerr << "SetText.txt could not be opened for reading!" << endl;
  866.         cerr << "Perezagruzi programmu" << endl;
  867.         Sleep(5000);
  868.         exit(1);
  869.     }
  870.  
  871. string z1, z2, z3, z4, z5, z6;
  872.     // Пока есть, что читать,
  873.     while (inf)
  874.     {
  875.        
  876.         // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
  877.         string strInput;
  878.         getline(inf, strInput);
  879.  
  880.         int ci = 0;
  881.         string word = "";
  882.         int probels = 0;
  883.        
  884.         while ((strInput[ci] != NULL)) {
  885.             strInput[ci];
  886.             if (strInput[ci] != ' ') { word += strInput[ci]; }
  887.             if ((strInput[ci] == ' ')||(strInput[ci+1] == NULL)) { probels++;
  888.                 switch(probels) {
  889.                     case 1:  z1 = word;
  890.                     case 2:  z2 = word;
  891.                     case 3:  z3 = word;
  892.                     case 4:  z4 = word;
  893.                     case 5:  z5 = word;
  894.                     case 6:  z6 = word;
  895.                     default: word = "";
  896.             }}
  897.                 ci++;
  898.         }
  899.         Node *s = getLast();
  900.         if (strInput != "\0") {s = Add(z1, z2, z3, z4, z5, z6, s); }   
  901.     }
  902.     Sleep(500);
  903.     //cout << nameFile << " - zagruzhen\nSoderzhanie: " << '"';
  904.     //std::system("pause");
  905.     //return strInput2;
  906. }
  907.  
  908. ///////////////////
  909. ////////////////
  910. string List::reedOfFile(string nameFile)
  911. {
  912.     ifstream inf(nameFile);
  913.     // Если мы не можем открыть файл для чтения его содержимого,
  914.     if (!inf)
  915.     {
  916.         // то выводим следующее сообщение об ошибке и выполняем функцию exit()
  917.         cerr << "SetText.txt could not be opened for reading!" << endl;
  918.         cerr << "Perezagruzi programmu" << endl;
  919.         Sleep(5000);
  920.         exit(1);
  921.     }
  922.     string strInput2;
  923.     // Пока есть, что читать,
  924.     while (inf)
  925.     {
  926.         // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
  927.         string strInput;
  928.         getline(inf, strInput);
  929.         strInput2 = strInput2 + strInput;
  930.     }
  931.     Sleep(500);
  932.     cout << nameFile << " - zagruzhen\nSoderzhanie: "<< '"';
  933.     //std::system("pause");
  934.     cout << strInput2;
  935.     cout << '"'<< endl;
  936.     return strInput2;
  937.    
  938. }
  939. ///////////////////
  940.  
  941. void List::Swap(Node* node1, Node* Otsenki)
  942. {
  943.     if (node1 == NULL || Otsenki == NULL) return;
  944.     if (node1 == Otsenki) return;
  945.     if (Otsenki->ptr == node1)
  946.     {
  947.         Node *p = node1;
  948.         node1 = Otsenki;
  949.         Otsenki = p;
  950.     }
  951.     Node *prev1 = Prev(node1);
  952.     Node *prev2 = Prev(Otsenki);
  953.     Node *next1 = Next(node1);
  954.     Node *next2 = Next(Otsenki);
  955.     if (next1 == Otsenki)
  956.     {
  957.         if (prev1 != NULL)
  958.             prev1->ptr = Otsenki;
  959.         else
  960.             head = Otsenki;
  961.         Otsenki->ptr = node1;
  962.         node1->ptr = next2;
  963.         return;
  964.     }
  965.     if (prev1 != NULL)
  966.         prev1->ptr = Otsenki;
  967.     else
  968.         head = Otsenki;
  969.     if (prev2 != NULL)
  970.         prev2->ptr = node1;
  971.     else
  972.         head = node1;
  973.     Otsenki->ptr = next1;
  974.     node1->ptr = next2;
  975. }
  976.  
  977.  
  978.  
  979. int main()
  980. {   //setlocate(LC_ALL, "Russian");
  981.     using std::string;
  982.     using std::cin;
  983.     using std::cout;
  984.     using std::getline;
  985.     SetConsoleOutputCP(1251);
  986.     SetConsoleCP(1251);
  987.     system("chcp 1251");
  988.     system("cls");
  989.    
  990.     List list;
  991.     Otsenki Otsenki;
  992.  
  993.     list.Print();
  994.     Node *s = list.getLast();
  995.     for (int i = 0; i < 0; i++) {
  996.         string z1;
  997.         string z2;
  998.         string z3;
  999.         string z4;
  1000.         string z5;
  1001.         string z6;
  1002.         cout << ">> N_student  ";
  1003.         cin >> z1;
  1004.         cout << ">> FirstName  ";
  1005.         cin >> z2;
  1006.         cout << ">> LastName  ";
  1007.         cin >> z3;
  1008.        
  1009.         cout << ">> fizika  ";
  1010.         cin >> z4;
  1011.         cout << ">> istoriya  ";
  1012.         cin >> z5;
  1013.         cout << ">> informatika  ";
  1014.         cin >> z6;
  1015.         s = list.Add(z1, z2, z3, z4, z5, z6, s);
  1016.     }
  1017.    
  1018.     //list.String_total_X();
  1019.    
  1020.     //list.reedOfFile("students.txt");
  1021. //list.ValidText("dfgdfgdf1");
  1022. //list.ValidChislo("АА1");
  1023.     //list.Delete_end();
  1024.     //list.Nomer_s_kontsa_del();
  1025.     //list.Del_By_value();
  1026.     //list.Print_By_value();
  1027.     //list.Delete_prev_end();
  1028.  
  1029.     //list.Zamena();
  1030.     //list.Zamena_ptr();
  1031.     //list.head_next_del();
  1032.     //list.Dobav_n_last();
  1033.     //list.Dobav_pre_last();
  1034.     list.StekOperation();
  1035.     //list.WriteFromProgToTxt();
  1036.     //list.ReedOfTxtToProg();
  1037.    
  1038.     //list.Dobav_head_next();
  1039.     //list.HeadToEnd();
  1040. //list.FILO();
  1041. //list.LIFO();
  1042.     //cout << "***********************" << endl;
  1043.     //list.Print();
  1044.     //cout << "Последний элемент: " << list.getValue(list.getLast()) << endl;
  1045.     // Удаляем элементы, равные 0
  1046.     //Node *p = list.getFirst();
  1047.     //do {
  1048.     //  if (list.getValue(p) == "0")
  1049.     //      p = list.Delete(p);
  1050.     //  else
  1051.     //      p = list.Next(p);
  1052.     //} while (p != NULL);
  1053.     //list.Print();
  1054.     //cout << "В списке " << list.getCount() << " элементов" << endl;
  1055.     //list.Swap(list.getFirst(), list.getLast());
  1056.     //list.Print();
  1057.     //list.Clear();
  1058.     list.Print();
  1059.     //cout << "В списке " << list.getCount() << " элементов" << endl;
  1060.     //cin.get(); cin.get();
  1061.    
  1062.    
  1063.  
  1064.     return 0;
  1065.  
  1066. }
  1067.  
  1068.  
  1069.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement