Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.71 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <iterator>
  5. #include <vector>
  6. #include <string>
  7. #include <sstream>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. class Cell
  12. {
  13. public:
  14.     string Data;
  15.     Cell *Nxt;
  16.  
  17.     Cell()
  18.     {
  19.         Data = "";
  20.         Nxt = NULL;
  21.     }
  22. };
  23.  
  24. class Row
  25. {
  26. public:
  27.     Cell* Head;
  28.     Cell* Tail;
  29.     Row* Nxt;
  30.  
  31.     Row()
  32.     {
  33.         Head = NULL;
  34.         Tail = NULL;
  35.  
  36.         for (int i = 0; i < 6; i++)
  37.         {
  38.             Cell *Tmp = new Cell;
  39.             if (this->Head == NULL)
  40.                 this->Head = this->Tail = Tmp;
  41.             else
  42.             {
  43.                 this->Tail->Nxt = Tmp;
  44.                 this->Tail = Tmp;
  45.             }
  46.         }
  47.     }
  48.  
  49.     ~Row()
  50.     {
  51.         while (Head != NULL)
  52.         {
  53.             Cell *Tmp = Head->Nxt;
  54.             delete Head;
  55.             Head = Tmp;
  56.         }
  57.         Tail = NULL;
  58.     }
  59. };
  60.  
  61. class TTable
  62. {
  63. public:
  64.     int RowNum;
  65.     Row* HeadPoint;
  66.     Row* TailPoint;
  67.  
  68.     TTable()
  69.     {
  70.         HeadPoint = NULL;
  71.     }
  72.  
  73.     ~TTable()
  74.     {
  75.         while (HeadPoint != NULL)
  76.         {
  77.             Row *Tmp = HeadPoint->Nxt;
  78.             delete HeadPoint;
  79.             HeadPoint = Tmp;
  80.         }
  81.         TailPoint = NULL;
  82.     }
  83.  
  84.     bool FileGet(string Path)
  85.     {
  86.         ifstream File_in(Path);
  87.  
  88.         if (File_in.is_open())
  89.         {
  90.             Row *TmpRow = new Row;
  91.             string Line;
  92.             while (getline(File_in, Line))
  93.             {
  94.                 stringstream StrStream;
  95.                 StrStream << Line;
  96.                 if (IsCorrect(Line))
  97.                 {
  98.                     if (HeadPoint == NULL)
  99.                         HeadPoint = TailPoint = TmpRow;
  100.                     else
  101.                     {
  102.                         TailPoint->Nxt = TmpRow;
  103.                         TailPoint = TmpRow;
  104.                     }
  105.                     string str;
  106.                     for (int i = 0; i < 6; i++)
  107.                     {
  108.                         StrStream >> str;
  109.                         Add(TmpRow, str);
  110.                     }
  111.  
  112.                     TmpRow->Nxt = new Row;
  113.                     TmpRow = TmpRow->Nxt;
  114.                     RowNum++;
  115.                 }
  116.                 else
  117.                     cout << "Ошибка чтения из файла\n";
  118.             }
  119.             File_in.close();
  120.             return true;
  121.         }
  122.         else
  123.         {
  124.             cout << "Файл не найден.";
  125.             return false;
  126.         }
  127.     }
  128.  
  129.     void FileSet(string Path)
  130.     {
  131.         ofstream File_out(Path);
  132.  
  133.         if (File_out.is_open())
  134.         {
  135.             string Line;   
  136.             int i = 0;
  137.             for (Row *TmpRow = HeadPoint; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, i++)
  138.             {
  139.                 string Line = RowStr(TmpRow);
  140.                 File_out << Line;
  141.                 if (i != RowNum - 1)
  142.                     File_out << '\n';
  143.             }
  144.  
  145.             File_out.close();
  146.         }
  147.         else
  148.         {
  149.             cout << "Файл не найден.";
  150.         }
  151.     }
  152.  
  153.     void Add(Row* row, string str)
  154.     {
  155.         Cell* Tmp = new Cell;
  156.         if (Tmp == NULL)
  157.             return;
  158.  
  159.         Tmp->Data = str;
  160.  
  161.         if (row->Head->Data == "")
  162.         {
  163.             row->Head = Tmp;
  164.             row->Tail = Tmp;
  165.         }
  166.         else
  167.         {
  168.             row->Tail->Nxt = Tmp;
  169.             row->Tail = Tmp;
  170.         }
  171.     }
  172.  
  173.     void AddRow()
  174.     {
  175.         cout << "Введите информацию о студенте:\n";
  176.         string row;
  177.         cin.ignore();
  178.         getline(cin, row);
  179.         if (IsCorrect(row))
  180.         {
  181.             stringstream StrStream;
  182.             StrStream << row;
  183.  
  184.             Row *TmpRow = new Row;
  185.  
  186.             if (HeadPoint == NULL)
  187.                 HeadPoint = TailPoint = TmpRow;
  188.             else
  189.             {
  190.                 TailPoint->Nxt = TmpRow;
  191.                 TailPoint = TmpRow;
  192.             }
  193.  
  194.             string str;
  195.             for (int i = 0; i < 6; i++)
  196.             {
  197.                 StrStream >> str;
  198.                 Add(TmpRow, str);
  199.             }
  200.             RowNum++;
  201.         }
  202.     }
  203.  
  204.     void DeleteRow()
  205.     {
  206.         int Val = 0;
  207.         cout << "Введите индекс столбца: "; cin >> Val;
  208.  
  209.         if (Val < 1 || Val > 6)
  210.         {
  211.             cout << "Неверный индекс\n";
  212.             return;
  213.         }
  214.  
  215.         string Data;
  216.         cout << "Введите значение: "; cin >> Data;
  217.  
  218.         int Position;
  219.         if (CellCheck(Data, Val))
  220.             Position = FindRow(Val, Data);
  221.         else
  222.             Position = -1;
  223.  
  224.         if (Position != -1)
  225.         {
  226.             Row* TmpRow = HeadPoint;
  227.  
  228.             if (Position == 0)
  229.             {
  230.                 HeadPoint = TmpRow->Nxt;
  231.                 free(TmpRow);
  232.                 return;
  233.             }
  234.  
  235.             for (int i = 0; TmpRow != NULL && i < Position - 1; i++)
  236.                 TmpRow = TmpRow->Nxt;
  237.  
  238.             if (TmpRow == NULL || TmpRow->Nxt == NULL)
  239.                 return;
  240.  
  241.             Row* Nxt = TmpRow->Nxt->Nxt;
  242.             free(TmpRow->Nxt);
  243.             TmpRow->Nxt = Nxt;
  244.             RowNum--;
  245.         }
  246.     }
  247.  
  248.     void ChangeRow()
  249.     {
  250.         int Val = 0;
  251.         cout << "Введите индекс столбца: "; cin >> Val;
  252.  
  253.         if (Val < 1 || Val > 6)
  254.         {
  255.             cout << "Неверный индекс\n";
  256.             return;
  257.         }
  258.  
  259.         string Data;
  260.         cout << "Введите значение: "; cin >> Data;
  261.  
  262.         int Position;
  263.         if (CellCheck(Data, Val))
  264.             Position = FindRow(Val, Data);
  265.         else
  266.             Position = -1;
  267.  
  268.         if (Position != -1)
  269.         {
  270.             Row* TmpRow = HeadPoint;
  271.             Row* Cur = HeadPoint;
  272.  
  273.             for (int i = 0; i < Position; i++)
  274.             {
  275.                 TmpRow = Cur;
  276.                 Cur = Cur->Nxt;
  277.             }
  278.  
  279.             if (Cur != NULL)
  280.             {
  281.                 cout << "Найденная строка:\n";
  282.                 PrntRow(Cur);
  283.                 cout << "Введите новую строку: \n";
  284.                 string Line;
  285.                 cin.ignore();
  286.                 while (true)
  287.                 {
  288.                     getline(cin, Line);
  289.  
  290.                     if (IsCorrect(Line))
  291.                     {
  292.                         Cell *TmpCell = Cur->Head;
  293.                         stringstream StrStream;
  294.                         StrStream << Line;
  295.                         string str;
  296.                         for (int i = 0; i < 6; i++)
  297.                         {
  298.                             StrStream >> str;
  299.                             TmpCell->Data = str;
  300.                             TmpCell = TmpCell->Nxt;
  301.                         }
  302.                         Cur = Cur->Nxt;
  303.                         break;
  304.                     }
  305.                     else
  306.                     {
  307.                         Line.clear();
  308.                         cout << "Введите строку еще раз: ";
  309.                     }
  310.                 }
  311.             }
  312.             else
  313.                 cout << "N/A";
  314.         }
  315.     }
  316.  
  317.     void Sort()
  318.     {
  319.         int Num;
  320.         cout << "Введите номер столбца: "; cin >> Num;
  321.         if (Num >= 1 && Num <= 6)
  322.         {
  323.             Row *rowHead = HeadPoint;
  324.             Row *FirstNode, *SecondNode;
  325.  
  326.             for (FirstNode = rowHead; FirstNode, FirstNode->Nxt; FirstNode = FirstNode->Nxt)
  327.             {      
  328.                 for (SecondNode = rowHead; SecondNode, SecondNode->Nxt; SecondNode = SecondNode->Nxt)
  329.                 {
  330.                     Cell *TmpCellFirst = FirstNode->Head;
  331.                     Cell *TmpCellSecond = SecondNode->Head;
  332.  
  333.                     for (int i = 0; i < Num - 1; i++)
  334.                     {
  335.                         TmpCellFirst = TmpCellFirst->Nxt;
  336.                         TmpCellSecond = TmpCellSecond->Nxt;
  337.                     }
  338.  
  339.                     if (strcmp(TmpCellFirst->Data.c_str(), TmpCellSecond->Data.c_str()) < 0)
  340.                         swap(FirstNode->Head, SecondNode->Head);
  341.                 }      
  342.             }              
  343.         }
  344.         else
  345.         {
  346.             cout << "Неверный номер элемента\n";
  347.             return;
  348.         }
  349.     }
  350.  
  351.     void Search()
  352.     {
  353.         int Value = 0, Colon = 0;
  354.         cout << "Введите номер столбца: ";
  355.         cin >> Colon;
  356.         cout << "\n";
  357.     cout << "По какому критерию будет проводиться поиск?\n";
  358.     cout << "Чтобы найти самый большой элемент, введите 1\n";
  359.     cout << "Чтобы найти самый маленький элемент, введите 2\n";
  360.     cout << "Чтобы найти первый четный элемент, введите 3\n";
  361.     cout << "Чтобы найти первый нечетный элемент, введите 4\n";
  362.     cout << "Чтобы найти первый положительный элемент, введите 5\n";
  363.     cout << "Чтобы найти первый отрицательный элемент, введите 6\n";
  364.     cout << "Чтобы найти все позиции указанного элемента, введите 7\n"; cin >> Value;
  365.  
  366.         if (Colon >= 1 && Colon <= 6)
  367.         {
  368.             switch (Value)
  369.             {
  370.                 case 1:
  371.                 {
  372.                     int max = 0;
  373.                     int Count = 0;
  374.                     Row *TmpRow = HeadPoint;
  375.                     int size = HeadPoint->Head->Data.size();
  376.                     for (; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, Count++)
  377.                     {
  378.                         Cell *TmpCell = TmpRow->Nxt->Head;
  379.                         for (int i = 0; i < Colon - 1; i++)
  380.                             TmpCell = TmpCell->Nxt;
  381.  
  382.                         if (TmpCell->Data.size() > size && TmpCell->Data.size() != 0)
  383.                         {
  384.                             size = TmpCell->Data.size();
  385.                             max = Count + 1;
  386.                         }
  387.                     }
  388.                     cout << "Самую большую строку содержит: " << max + 1 << "-й столбец\n";
  389.                     break;
  390.                 }
  391.                 case 2:
  392.                 {
  393.                     int min  = 0;
  394.                     int Count = 0;
  395.                     Row *TmpRow = HeadPoint;
  396.                     int size = HeadPoint->Head->Data.size();
  397.                    
  398.                     for (; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, Count++)
  399.                     {
  400.                         Cell *TmpCell = TmpRow->Nxt->Head;
  401.                         for (int i = 0; i < Colon - 1; i++)
  402.                             TmpCell = TmpCell->Nxt;
  403.  
  404.                         if (TmpCell->Data.size() < size && TmpCell->Data.size() != 0)
  405.                         {
  406.                             size = TmpCell->Data.size();
  407.                             min = Count + 1;
  408.                         }
  409.                     }
  410.                     cout << "Самую маленькую строку содержит: " << min + 1 << "-й столбец\n";
  411.                     break;
  412.                 }
  413.                 case 3:
  414.                 {
  415.                     system("cls");
  416.                     int Even = 0;
  417.                     int Count = 0;
  418.                     Row *TmpRow = HeadPoint;
  419.                     for (; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, Count++)
  420.                     {
  421.                         Cell *TmpCell = TmpRow->Head;
  422.                         for (int i = 0; i < Colon - 1; i++)
  423.                             TmpCell = TmpCell->Nxt;
  424.  
  425.                         if (TmpCell->Data.size() % 2 == 0 && TmpCell->Data.size() != 0)
  426.                         {
  427.                             Even = Count + 1;
  428.                             break;
  429.                         }                          
  430.                     }
  431.                     if (Even != 0)
  432.                         cout << "Первую четную строку содержит " << Even << "-й столбец\n";
  433.                     else
  434.                         cout << "Четные элементы отсутствуют" << "\n\n";
  435.                     break;
  436.                 }
  437.                 case 4:
  438.                 {
  439.                     system("cls");
  440.                     int Uneven = 0;
  441.                     int Count = 0;
  442.                     Row *TmpRow = HeadPoint;
  443.                     for (; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, Count++)
  444.                     {
  445.                         Cell *TmpCell = TmpRow->Head;
  446.                         for (int i = 0; i < Colon - 1; i++)
  447.                             TmpCell = TmpCell->Nxt;
  448.  
  449.                         if (TmpCell->Data.size() % 2 != 0 && TmpCell->Data.size() != 0)
  450.                         {
  451.                             Uneven = Count + 1;
  452.                             break;
  453.                         }
  454.                     }
  455.                     if (Uneven != 0)
  456.                         cout << "Первую нечетную строку содержит " << Uneven << "-й столбец\n";
  457.                     else
  458.                         cout << "Нечетные элементы отсутствуют" << "\n\n";
  459.                     break;
  460.                 }
  461.                 case 5:
  462.                 {
  463.                     system("cls");
  464.                     int Plus = 0;
  465.  
  466.                     int Count = 0;
  467.                     Row *TmpRow = HeadPoint;
  468.                     for (; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, Count++)
  469.                     {
  470.                         Cell *TmpCell = TmpRow->Head;
  471.                         for (int i = 0; i < Colon - 1; i++)
  472.                             TmpCell = TmpCell->Nxt;
  473.  
  474.                         if (TmpCell->Data.size() > 0 && TmpCell->Data.size() != 0)
  475.                         {
  476.                             Plus = Count + 1;
  477.                             break;
  478.                         }
  479.                     }
  480.                     if (Plus != 0)
  481.                         cout << "Первую положительную строку содержит " << Plus << "-й столбец\n";
  482.                     else
  483.                         cout << "Положительные элементы отсутствуют" << "\n\n";
  484.                     break;
  485.                 }
  486.                 case 6:
  487.                 {
  488.                     system("cls");
  489.                     int Minus = 0;
  490.  
  491.                     int Count = 0;
  492.                     Row *TmpRow = HeadPoint;
  493.                     for (; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, Count++)
  494.                     {
  495.                         Cell *TmpCell = TmpRow->Head;
  496.                         for (int i = 0; i < Colon - 1; i++)
  497.                             TmpCell = TmpCell->Nxt;
  498.  
  499.                         if (TmpCell->Data.size() < 0 && TmpCell->Data.size() != 0)
  500.                         {
  501.                             Minus = Count + 1;
  502.                             break;
  503.                         }
  504.                     }
  505.                     if (Minus != 0)
  506.                         cout << "Первую отрицательную строку содержит " << Minus << "-й столбец\n";
  507.                     else
  508.                         cout << "Отрицательные элементы отсутствуют" << "\n\n";
  509.                     break;
  510.                 }
  511.                 case 7:
  512.                 {
  513.                     system("cls");
  514.                     string str = "";
  515.                     cout << "Введите строку: "; cin >> str;
  516.                     cout << "Все позиции узазанной строки: ";
  517.                     int Count = 0;
  518.                     Row *TmpRow = HeadPoint;
  519.                     for (; TmpRow, TmpRow->Nxt; TmpRow = TmpRow->Nxt, Count++)
  520.                     {
  521.                         Cell *TmpCell = TmpRow->Head;
  522.                         for (int i = 0; i < Colon - 1; i++)
  523.                             TmpCell = TmpCell->Nxt;
  524.  
  525.                         if (strcmp(TmpCell->Data.c_str(), str.c_str()) == 0 && TmpCell->Data.size() != 0)
  526.                             cout << Count + 1 << ", ";
  527.                     }
  528.                     cout << "\n\n";
  529.                     break;
  530.                 }
  531.                 default: cout << "\n...Не то число...\n\n";
  532.             }
  533.         }
  534.         else
  535.         {
  536.             cout << "Неверный номер столбца";
  537.         }
  538.     }
  539.  
  540.     void Print()
  541.     {
  542.         if (HeadPoint == NULL)
  543.             return;
  544.  
  545.         Row *TmpRow = HeadPoint;
  546.         cout << "\n\n  " << setw(19) << "1.Фамилия" << setw(19) << "2.Имя" << setw(19) << "3.Группа" << setw(19) << "4.Специальность" << setw(19) << "5.Год рождения" << setw(19) << "6.Телефон";
  547.         cout << '\n';
  548.         int i = 0;
  549.         while (TmpRow && TmpRow->Nxt)
  550.         {
  551.             cout << i + 1 << '.';
  552.             PrntRow(TmpRow);
  553.             TmpRow = TmpRow->Nxt;
  554.             i++;
  555.         }
  556.         cout << "\n";
  557.     }
  558.  
  559.     void PrntRow(Row* row)
  560.     {
  561.         if (row == NULL)
  562.             return;
  563.  
  564.         Cell *TmpCell = row->Head;
  565.  
  566.         while (TmpCell)
  567.         {
  568.             cout << setw(19) << TmpCell->Data;
  569.             TmpCell = TmpCell->Nxt;
  570.         }
  571.         cout << '\n';
  572.     }
  573.  
  574.     bool CellCheck(string Data, int Position)
  575.     {
  576.         switch (Position)
  577.         {
  578.         case 1:
  579.         {
  580.             if (!IsSurname(Data))
  581.                 return false;
  582.             else
  583.                 return true;
  584.         }
  585.         case 2:
  586.         {
  587.             if (!IsName(Data))
  588.                 return false;
  589.             else
  590.                 return true;
  591.         }
  592.         case 3:
  593.         {
  594.             if (!IsGroup(Data))
  595.                 return false;
  596.             else
  597.                 return true;
  598.         }
  599.         case 4:
  600.         {
  601.             if (!IsSpecialty(Data))
  602.                 return false;
  603.             else
  604.                 return true;
  605.         }
  606.         case 5:
  607.         {
  608.             if (!IsBirthYear(Data))
  609.                 return false;
  610.             else
  611.                 return true;
  612.         }
  613.         case 6:
  614.         {
  615.             if (!IsPhoneNumber(Data))
  616.                 return false;
  617.             else
  618.                 return true;
  619.         }
  620.         default: cout << "\nНеверный индекс\n";
  621.         }
  622.     }
  623.  
  624.     int FindRow(int ColonNum, string Data)
  625.     {
  626.         if (HeadPoint == NULL)
  627.             return -1;
  628.  
  629.         Row* TmpRow = HeadPoint;
  630.         int Position = 0;
  631.         while (TmpRow)
  632.         {
  633.             Cell* TmpCell = TmpRow->Head;
  634.             for (int i = 0; i < ColonNum; i++)
  635.             {
  636.                 if (strcmp(TmpCell->Data.c_str(), Data.c_str()) == 0)
  637.                     return Position;
  638.                 TmpCell = TmpCell->Nxt;
  639.             }
  640.             TmpRow = TmpRow->Nxt;
  641.             Position++;
  642.         }
  643.         cout << "\nЗначение не найдено\n";
  644.         return -1;
  645.     }
  646.  
  647.     string CellDataSearch(Row* row, int Position)
  648.     {
  649.         Cell* TmpCell = row->Head;
  650.         for (int i = 0; i < Position - 1; i++)
  651.         {
  652.             TmpCell = TmpCell->Nxt;
  653.         }
  654.         return TmpCell->Data;
  655.     }
  656.  
  657.     bool IsCorrect(string Line)
  658.     {
  659.         stringstream StrStream; StrStream << Line;
  660.         string str;
  661.         StrStream >> str;
  662.         if (!IsSurname(str))
  663.             return false;
  664.         StrStream >> str;
  665.         if (!IsName(str))
  666.             return false;
  667.         StrStream >> str;
  668.         if (!IsGroup(str))
  669.             return false;
  670.         StrStream >> str;
  671.         if (!IsSpecialty(str))
  672.             return false;
  673.         StrStream >> str;
  674.         if (!IsBirthYear(str))
  675.             return false;
  676.         StrStream >> str;
  677.         if (!IsPhoneNumber(str))
  678.             return false;
  679.         return true;
  680.     }
  681.  
  682.     string RowStr(Row* row)
  683.     {
  684.         string str;
  685.         Cell* TmpCell = row->Head;
  686.         for (int i = 0; i < 6; TmpCell = TmpCell->Nxt, i++)
  687.         {
  688.             if (i != 5)
  689.                 str += TmpCell->Data + ' ';
  690.             else
  691.             {
  692.                 str += TmpCell->Data;
  693.             }
  694.         }
  695.         return str;
  696.     }
  697.  
  698.     bool IsSurname(string Surname)
  699.     {
  700.         if (Surname.length() > 20)
  701.         {
  702.             cout << "Слишком длинная фамилия\n";
  703.             return false;
  704.         }
  705.         for (int i = 0; i < Surname.length(); i++)
  706.         {
  707.             if (((Surname[i] < 65 || Surname[i] > 122) || (Surname[i] > 90 && Surname[i] < 97)) && Surname[i] != '-')
  708.             {
  709.                 cout << "Некорректный символ: " << Surname[i] << '\n';
  710.                 return false;
  711.             }
  712.         }
  713.         return true;
  714.     }
  715.  
  716.     bool IsName(string Name)
  717.     {
  718.         if (Name.length() > 10)
  719.         {
  720.             cout << "Слишком длинное имя\n";
  721.             return false;
  722.         }
  723.         for (int i = 0; i < Name.length(); i++)
  724.         {
  725.             if ((Name[i] < 65 || Name[i] > 122) || (Name[i] > 90 && Name[i] < 97))
  726.             {
  727.                 cout << "Некорректный символ: " << Name[i] << '\n';
  728.                 return false;
  729.             }
  730.         }
  731.         return true;
  732.     }
  733.  
  734.     bool IsGroup(string Group)
  735.     {
  736.         if (Group.length() > 10)
  737.         {
  738.             cout << "Слишком длинное название группы\n";
  739.             return false;
  740.         }
  741.         for (int i = 0; i < Group.length(); i++)
  742.         {
  743.             if (((Group[i] < 48 || Group[i] > 122) || (Group[i] > 57 && Group[i] < 65) || (Group[i] > 90 && Group[i] < 97)) && Group[i] != '-')
  744.             {
  745.                 cout << "Некорректный символ: " << Group[i] << '\n';
  746.                 return false;
  747.             }
  748.         }
  749.         return true;
  750.     }
  751.  
  752.     bool IsSpecialty(string Speciality)
  753.     {
  754.         if (Speciality.length() > 30)
  755.         {
  756.             cout << "Слишком длинное название специальности\n";
  757.             return false;
  758.         }
  759.         for (int i = 0; i < Speciality.length(); i++)
  760.         {
  761.             if ((Speciality[i] < 65 || Speciality[i] > 122) || (Speciality[i] > 90 && Speciality[i] < 97))
  762.             {
  763.                 cout << "Некорректный символ: " << Speciality[i] << '\n';
  764.                 return false;
  765.             }
  766.         }
  767.         return true;
  768.     }
  769.  
  770.     bool IsBirthYear(string BirthYear)
  771.     {
  772.         if (BirthYear.length() != 4)
  773.         {
  774.             cout << "Некорректный год\n";
  775.             return false;
  776.         }
  777.         for (int i = 0; i < BirthYear.length(); i++)
  778.         {
  779.             if (BirthYear[i] < 48 || BirthYear[i] > 57)
  780.             {
  781.                 cout << "Некорректный символ: " << BirthYear[i] << '\n';
  782.                 return false;
  783.             }
  784.         }
  785.         return true;
  786.     }
  787.  
  788.     bool IsPhoneNumber(string PhoneNumber)
  789.     {
  790.         if (PhoneNumber.length() != 10)
  791.         {
  792.             cout << "Некорректный номер\n";
  793.             return false;
  794.         }
  795.         for (int i = 0; i < PhoneNumber.length(); i++)
  796.         {
  797.             if (PhoneNumber[i] < 48 || PhoneNumber[i] > 57)
  798.             {
  799.                 cout << "Некорректный символ: " << PhoneNumber[i] << '\n';
  800.                 return false;
  801.             }
  802.         }
  803.         return true;
  804.     }
  805.  
  806.     void Actions(string Path)
  807.     {
  808.         int Value = 0;
  809.         do
  810.         {
  811.             cout << "Выбирайте действие:\n";
  812.             cout << "Чтобы добавить элемент в массив, введите 1\n";
  813.             cout << "Чтобы удалить элемент из массива, введите 2\n";
  814.             cout << "Чтобы заменить элемент в массиве, введите 3\n";
  815.             cout << "Чтобы сортировать массив, введите 4\n";
  816.             cout << "Чтобы искать элемент в массиве, введите 5\n";
  817.             cout << "Чтобы вывести таблицу на экран, введите 6\n";
  818.             cout << "Чтобы покинуть программу, введите любой другой символ\n";
  819.             cout << "Ваше действие: "; cin >> Value;
  820.             switch (Value)
  821.             {
  822.             case 1:
  823.             {
  824.                 system("cls");
  825.                 AddRow();
  826.                 FileSet(Path);
  827.                 Print();
  828.                 break;
  829.             }
  830.             case 2:
  831.             {
  832.                 system("cls");
  833.                 DeleteRow();
  834.                 FileSet(Path);
  835.                 Print();
  836.                 break;
  837.             }
  838.             case 3:
  839.             {
  840.                 system("cls");
  841.                 ChangeRow();
  842.                 FileSet(Path);
  843.                 Print();
  844.                 break;
  845.             }
  846.             case 4:
  847.             {
  848.                 system("cls");
  849.                 Sort();
  850.                 FileSet(Path);
  851.                 Print();
  852.                 break;
  853.             }
  854.             case 5:
  855.             {
  856.                 system("cls");
  857.                 Search();
  858.                 Print();
  859.                 break;
  860.             }
  861.             case 6:
  862.             {
  863.                 system("cls");
  864.                 Print();
  865.                 break;
  866.             }
  867.             default: cout << "Всего доброго!\n";
  868.             }
  869.  
  870.         } while (Value > 0 && Value < 7);
  871.     }
  872. };
  873.  
  874. int main()
  875. {
  876.     setlocale(LC_ALL, "Russian");
  877.  
  878.     string Path = "D:\\C#\\DB_Lab-4\\DB_Lab-4\\Students.txt";
  879.  
  880.     TTable NewTable;
  881.     if (NewTable.FileGet(Path))
  882.         NewTable.Actions(Path);
  883.  
  884.     system("pause");
  885.     return 0;
  886. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement