Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <string>
  5. #include <windows.h>
  6. #include <conio.h>
  7. #include <stdio.h>
  8. #include <cwchar>
  9. #include <winuser.h>
  10. #include <tchar.h>
  11. using namespace std;
  12. //===============================================Global_Elemenst====================================================================================
  13. string File_name;
  14. float total_elements = 0;
  15. int num_pages = 5,
  16. width = 0,
  17. height = 0,
  18. num_el = 0;
  19. //===============================================Menu_Names===================================================================================
  20. const string items[14] = {
  21.     "   Add              ",
  22.     "   Delete All       ",
  23.     "   Delete First     ",
  24.     "   View             ",
  25.     "   Read File(txt)   ",
  26.     "   Save File(txt)   ",
  27.     "   Read File(bin)   ",
  28.     "   Save File(bin)   ",
  29.     "   Search           ",
  30.     "   Sort             ",
  31.     "   My Function      ",
  32.     "   Delete By Number ",
  33.     "   Edit             ",
  34.     "   Exit             " };
  35. //===============================================Sort_Names===================================================================================
  36. const string sort_items[6] = {
  37.     " Name     ",
  38.     " Birthday ",
  39.     " Sex      ",
  40.     " Weight   ",
  41.     " Rank     ",
  42.     " Team     " };
  43. //===============================================Buttons===================================================================================
  44. const int up = 72,
  45. down = 80,
  46. right_btn = 77,
  47. left_btn = 75,
  48. enter = 13,
  49. esc = 27,
  50. del = 83;
  51. //===============================================Data==================================================================================
  52. struct info {
  53.     string Name;
  54.     string Birthday;
  55.     string Sex;
  56.     string Weight;
  57.     string Rank;
  58.     string Team;
  59. };
  60. //===============================================List====================================================================================================
  61. struct Sportsman {
  62.     info D;
  63.     Sportsman* next = 0;
  64.     Sportsman* prev = 0;
  65. };
  66. //===============================================Interface===================================================================================
  67. Sportsman* Add(Sportsman* right, const Sportsman& S);
  68. Sportsman* Add_first(const Sportsman& S);
  69. Sportsman* Del(Sportsman* left);
  70. Sportsman Information();
  71. void Print(const Sportsman& S);
  72. void Watch(Sportsman* left);
  73. void Read_File(string File_name, Sportsman** left, Sportsman** right);
  74. void Write_File(string File_name, Sportsman* left);
  75. void SetColor(int text, int bg);
  76. void print_menu(int sym, const string items[], const int N_ITEMS);
  77. void cls();
  78. void gotoxy(int xpos, int ypos);
  79. int menu(int& active, const string items[], int num_el);
  80. int Read_Bin_File(string filename, Sportsman** left, Sportsman** right);
  81. void Write_Bin_File(string File_name, Sportsman* left);
  82. void clearRow(int row);
  83. void Search(Sportsman* left);
  84. void Sort(Sportsman* left, int sort_active);
  85. void My_Function(Sportsman* left);
  86. Sportsman* delete_By_Number(Sportsman* left);
  87. Sportsman* Edit(Sportsman* left, int Edit_Field);
  88. //===============================================_Main_===================================================================================
  89. int main() {
  90.     SetColor(7, 0);
  91.     Sportsman* left = 0,
  92.         * right = 0;
  93.     //========================================Width/height_OF_Window===========================================================================
  94.     HANDLE hCon;
  95.     hCon = GetStdHandle(-12);
  96.     CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
  97.     if (GetConsoleScreenBufferInfo(hCon, &consoleInfo))
  98.     {
  99.         width = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1;
  100.         height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
  101.     }
  102.     //========================================Open_Full_Winodw===========================================================================
  103.     ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
  104.     //============================================Case=========================================================================================
  105.     int current = 1;
  106.     int sort_active = 0;
  107.     int current_sort = 1;
  108.     int Ed = 0;
  109.     Read_File("1.txt", &left, &right);
  110.     while (1)
  111.     {
  112.         switch (menu(current, items, 14))
  113.         {
  114.         case 1:
  115.             system("cls");
  116.             if (left) right = Add(right, Information());
  117.             else {
  118.                 left = Add_first(Information());
  119.                 right = left;
  120.             } break;
  121.         case 2:
  122.             system("cls");
  123.             while (left)
  124.                 left = Del(left);
  125.             cout << "Press any key" << endl;
  126.             cin.get();
  127.             break;
  128.         case 3:
  129.             system("cls");
  130.             left = Del(left);
  131.             cout << "Press any key" << endl;
  132.             cin.get();
  133.             break;
  134.         case 4:
  135.             system("cls");
  136.             Watch(left);
  137.             break;
  138.  
  139.         case 5:
  140.             system("cls");
  141.             cout << "Choose Name of the File" << endl;
  142.             cin >> File_name;
  143.             Read_File(File_name, &left, &right);
  144.             break;
  145.         case 6:
  146.             system("cls");
  147.             cout << "Choose Name of the File" << endl;
  148.             cin >> File_name;
  149.             Write_File(File_name, left);
  150.             break;
  151.         case 7:
  152.             system("cls");
  153.             cout << "Choose Name of the File" << endl;
  154.             cin >> File_name;
  155.             Read_Bin_File(File_name, &left, &right);
  156.             break;
  157.         case 8:
  158.             system("cls");
  159.             cout << "Choose Name of the File" << endl;
  160.             cin >> File_name;
  161.             Write_Bin_File(File_name, left);
  162.             break;
  163.         case 9:
  164.             system("cls");
  165.             Search(left);
  166.             system("pause");
  167.             break;
  168.         case 10:
  169.             system("cls");
  170.             sort_active = menu(current_sort, sort_items, 6);
  171.             MessageBox(0, "It was sorted!", "Information", MB_ICONINFORMATION | MB_SETFOREGROUND);
  172.             Sort(left, sort_active);
  173.             break;
  174.         case 11:
  175.             system("cls");
  176.             My_Function(left);
  177.             break;
  178.         case 12:
  179.                 system("cls");
  180.                 left = delete_By_Number(left);
  181.                 break;
  182.         case 13:
  183.             system("cls");
  184.             Ed = menu(current_sort, sort_items, 6);
  185.             system("cls");
  186.              Edit(left, Ed);
  187.             break;
  188.         case -1:
  189.         case 14:
  190.             return 0;
  191.             break;
  192.         }
  193.     }
  194. }
  195. //=============================================Functions==================================================================================
  196. //=============================================Add========================================================================================
  197. Sportsman* Add(Sportsman* right, const Sportsman& S) {
  198.     Sportsman* newE = new Sportsman;
  199.     *newE = S;
  200.     newE->next = 0;
  201.     newE->prev = right;
  202.     right->next = newE;
  203.     right = newE;
  204.     return right;
  205. }
  206. //=============================================Add_First====================================================================================
  207. Sportsman* Add_first(const Sportsman& S) {
  208.     Sportsman* left = new Sportsman;
  209.     *left = S;
  210.     left->next = 0;
  211.     left->prev = 0;
  212.     return left;
  213. }
  214. //=============================================Delete=================================================================================
  215. Sportsman* Del(Sportsman* left) {
  216.     Sportsman* temp;
  217.     if (!left) { cout << "Empty" << endl; return 0; }
  218.     else {
  219.         temp = left;
  220.         left = left->next;
  221.         delete temp;
  222.     }
  223.     total_elements--;
  224.     return left;
  225. }
  226. //=============================================Information=================================================================================
  227. Sportsman Information() {
  228.     struct Sportsman S;
  229.     boolean logic = 1;
  230.     cout << "Choose Name(15 Symbols)" << endl;
  231.     int max_length = 15;
  232.     do {
  233.         try {
  234.             getline(cin, S.D.Name);
  235.             for (int i = 0; i < S.D.Name.length(); i++)
  236.                 if ((S.D.Name[i] >= '0' && S.D.Name[i] <= '9') || S.D.Name.length() > max_length)      
  237.                     throw 1;
  238.             break;
  239.         }  
  240.         catch(int Y){
  241.         MessageBox(0, "Wrong Name", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  242.         gotoxy(0, 1);
  243.         clearRow(2);
  244.         }
  245.     } while (true);
  246.     cout << "Choose Birthday (1900-2010)" << endl;
  247.     do {
  248.         int length = 0;
  249.         int pospos = 0;
  250.         int posarrays[8] = { 0, 1, 3, 4, 6, 7, 8, 9 };
  251.         int pos = posarrays[pospos];
  252.         S.D.Birthday = "__.__.____";
  253.         cout << S.D.Birthday;
  254.         while (length != 8) {
  255.             int ch = _getch();
  256.             if (ch == 8 && length != 0) {
  257.                 length--;
  258.                 S.D.Birthday[pos - ((length == 3 || length == 1) ? 2 : 1)] = '_';
  259.                 gotoxy(0, 3);
  260.                 pospos--;
  261.                 pos = posarrays[pospos];
  262.                 cout << S.D.Birthday;
  263.             }
  264.             else if (ch >= '0' && ch <= '9') {
  265.                 length++;
  266.                 S.D.Birthday[pos] = ch;
  267.                 gotoxy(0, 3);
  268.                 pospos++;
  269.                 pos = posarrays[pospos];
  270.                 cout << S.D.Birthday;
  271.             }
  272.         }
  273.         int Day = stoi(S.D.Birthday.substr(0, 2));
  274.         int Month = stoi(S.D.Birthday.substr(3, 2));
  275.         int Year = stoi(S.D.Birthday.substr(6, 4));
  276.         int days_in_month[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
  277.         if (Year % 4 == 0)
  278.             days_in_month[2] = 29;
  279.         if ((Month < 1) || (Month > 12))
  280.             MessageBox(0, "Wrong Month!", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  281.         else if ((Day < 1) || (Day > days_in_month[Month]))
  282.             MessageBox(0, "Wrong Day!", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  283.         else if ((Year > 2010) || (Year < 1900))
  284.             MessageBox(0, "Wrong Year!", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  285.         else break;
  286.         gotoxy(0, 3);
  287.         clearRow(4);
  288.     } while (true);
  289.     cout << "\nChoose Sex (M/F)" << endl;
  290.     do {
  291.         getline(cin, S.D.Sex);
  292.         if ((S.D.Sex == "M") || (S.D.Sex == "F"))
  293.             break;
  294.         else
  295.             MessageBox(0, "There is no Sex like that!", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  296.         gotoxy(0, 5);
  297.         clearRow(6);
  298.     } while (true);
  299.     cout << "Choose Weight (40..150)" << endl;
  300.     do {
  301.         try {
  302.             getline(cin, S.D.Weight);
  303.             int Max_Weight = 3;
  304.             int count = 0;
  305.             for (int i = 0; i < S.D.Weight.length(); i++) {
  306.                 if (!(S.D.Weight[i] >= '0' && S.D.Weight[i] <= '9'))
  307.                     throw 1;
  308.             }
  309.             if (!(stoi(S.D.Weight) >= 40 && stoi(S.D.Weight) <= 150))
  310.                 throw 1;
  311.             break;
  312.  
  313.         }
  314.         catch (int X) {
  315.             if (X == 1) {
  316.                 MessageBox(0, "Wrong Weight", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  317.             }
  318.             gotoxy(0, 7);
  319.             clearRow(8);
  320.         }
  321.     } while (true);
  322.     cout << "Choose Rank (1..5)" << endl;
  323.     do {
  324.         try {
  325.             getline(cin, S.D.Rank);
  326.             for (int i = 0; i < S.D.Rank.length(); i++) {
  327.                 if (!(S.D.Rank[i] >= '0' && S.D.Rank[i] <= '9'))
  328.                     throw 1;
  329.             }
  330.             if (!(stoi(S.D.Rank) >= 1 && stoi(S.D.Rank) <= 5))
  331.                 throw 1;
  332.             break;
  333.  
  334.         }
  335.         catch (int X) {
  336.             if (X == 1) {
  337.                 MessageBox(0, "Wrong Rank", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  338.             }
  339.             gotoxy(0, 9);
  340.             clearRow(10);
  341.         }
  342.     } while (true);
  343.     cout << "Choose Team (15 Symbols)" << endl;
  344.     do {
  345.         getline(cin, S.D.Team);
  346.         if (S.D.Team.length() <= max_length)
  347.             break;
  348.         else
  349.             MessageBox(0, "To many Symbols!", "Warning", MB_ICONWARNING | MB_SETFOREGROUND); {
  350.             gotoxy(0, 11);
  351.             clearRow(12); }
  352.     } while (true);
  353.  
  354.     total_elements++;
  355.     return S;
  356. }
  357. // =========================================================Clear_Row==================================================================================
  358. void clearRow(int row)
  359. {
  360.     DWORD a;
  361.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  362.     COORD coord = { 0, row - 1 };
  363.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  364.     GetConsoleScreenBufferInfo(hStdOut, &csbi);
  365.     FillConsoleOutputCharacter(hStdOut, ' ', 80, coord, &a);
  366. }
  367. // =====================================================Gotoxy================================================================================
  368. void gotoxy(int xpos, int ypos)
  369. {
  370.     COORD scrn;
  371.     HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
  372.     scrn.X = xpos; scrn.Y = ypos;
  373.     SetConsoleCursorPosition(hOuput, scrn);
  374. }
  375. //===================================================SetColor===================================================================
  376. void SetColor(int text, int bg) {
  377.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  378.     SetConsoleTextAttribute(hStdOut, (WORD)((bg << 4) | text));
  379. }
  380. //===================================================Print_Menu=====================================================================
  381. void print_menu(int sym, const string items[], const int N_ITEMS) {
  382.     for (int i = 1; i <= N_ITEMS; i++) {
  383.         SetColor(7, 0);
  384.         gotoxy((width ) - 6, (height) + i - 3);
  385.         if (i == sym) {
  386.             SetColor(7, 12);
  387.         }
  388.         cout << items[i - 1] << endl;
  389.         SetColor(7, 0);
  390.     }
  391. }
  392. //=====================================================================Menu===================================================
  393. int menu(int& active, const string items[], int num_el) {
  394.     wint_t buf;
  395.     do {
  396.         system("cls");
  397.         print_menu(active, items, num_el);
  398.         buf = _getwch();
  399.         switch (buf) {
  400.         case up:
  401.             if (active > 1) active--;
  402.             break;
  403.         case down:
  404.             if (active < num_el) active++;
  405.             break;
  406.         case enter:
  407.             return active;
  408.         case esc:
  409.             return -1;
  410.         case del:
  411.             return -active;
  412.         }
  413.     } while (1);
  414. }
  415.  
  416. // ==============================================АНАЛОГ setw()==================================================================================
  417. string sets(size_t size) {
  418.     string res_s;
  419.     for (int i = 0; i < size; i++) {
  420.         res_s += " ";
  421.     }
  422.     return res_s;
  423. }
  424. //===============================================Print=================================================================================
  425. void Print(const Sportsman& S) {
  426.     if (num_el >= 9 && num_el <= 99) {
  427.         cout << " " << ++num_el << "  ";
  428.     }
  429.     else if (num_el >= 100 && num_el <= 999) {
  430.         cout << " " << ++num_el << " ";
  431.     }
  432.     else {
  433.         cout << " " << ++num_el << "   ";
  434.     }
  435.     cout << "|" << S.D.Name << setw(30 - S.D.Name.length()) << " | ";
  436.     cout << S.D.Birthday << " | ";
  437.     cout << " " << S.D.Sex << "  | ";
  438.     cout << S.D.Weight << setw(9 - S.D.Weight.length()) << " | ";
  439.     cout << S.D.Rank << "    | ";
  440.     cout << S.D.Team << setw(20 - S.D.Team.length()) << " | " << endl;
  441. }
  442.  
  443. int key = 0;
  444.  
  445. //===============================================Watch=================================================================================
  446. void Watch(Sportsman* left) {
  447.     if (!left) { cout << "Empty" << endl; cin.get(); return; }
  448.     Sportsman* temp = left,
  449.         * first_prev_el = left,
  450.         * temp_el = left,
  451.         * first_temp_el = left;
  452.  
  453.     int count_el_on_page = 0,
  454.         i = 0,
  455.         first_el = 0,
  456.         page = 1,
  457.         fl = 0,
  458.         keycode = 0;
  459.  
  460.     do {
  461.         float total_pages = ceil(total_elements / 10);
  462.  
  463.         if (count_el_on_page != total_elements) {
  464.             cout << " №   " << "|";
  465.             cout << "Name" << setw(25) << "|";
  466.             cout << " Birthday" << setw(4) << "|";
  467.             cout << " Sex " << "|";
  468.             cout << " Weight " << "|";
  469.             cout << " Rank " << "|";
  470.             cout << " Team " << setw(14) << "|" << endl;
  471.             cout << "==========================================================================================" << endl;
  472.  
  473.             for (; temp; temp = temp->next) {
  474.                 if (count_el_on_page == (page - 1) * 10 + 1) {
  475.                     first_temp_el = temp->prev;
  476.                 }
  477.                 if (page != 1) {
  478.                     if (first_el != 1) {
  479.                         temp_el = temp;
  480.                         for (int j = 0; j < 10; j++, temp = temp->prev) {
  481.                             first_prev_el = temp->prev;
  482.                         }
  483.                         temp = temp_el;
  484.                         first_el++;
  485.                     }
  486.                 }
  487.  
  488.                 Print(*temp);
  489.                 count_el_on_page++;
  490.                 if (count_el_on_page % 10 == 0) {
  491.                     temp = temp->next;
  492.                     break;
  493.                 }
  494.             }
  495.             cout << "==========================================================================================" << endl;
  496.             cout << "               " << "Page " << page << " of " << setprecision(0) << total_pages;
  497.         }
  498.         int control = _getwch();
  499.         if (control == esc) {
  500.             num_el = 0;
  501.             return;
  502.         }
  503.         keycode = _getwch();
  504.  
  505.         switch (keycode) {
  506.         case right_btn:
  507.             if (count_el_on_page != total_elements) {
  508.                 system("cls");
  509.                 page++;
  510.                 first_el = 0;
  511.             }
  512.             break;
  513.         case left_btn:
  514.             if (page >= 2) {
  515.                 page--;
  516.             }
  517.             num_el = (page - 1) * 10;
  518.             first_el = 0;
  519.             count_el_on_page = (page - 1) * 10;
  520.             temp = first_prev_el;
  521.             system("cls");
  522.             break;
  523.         default:
  524.             temp = first_temp_el;
  525.             system("cls");
  526.             break;
  527.         }
  528.     } while (1);
  529.  
  530. }
  531. //===============================================CLS=================================================================================
  532. void cls() {
  533.     HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
  534.     COORD cd;
  535.     cd.X = 0;
  536.     cd.Y = 0;
  537.     SetConsoleCursorPosition(hd, cd);
  538. }
  539. //===============================================Read_File=================================================================================
  540. void Read_File(string File_name, Sportsman** left, Sportsman** right) {
  541.     total_elements = 0;
  542.  
  543.     ifstream File_in;
  544.     File_in.open(File_name);
  545.     if (!File_in) {
  546.         MessageBox(0, "Trere is no File!", "ERROR", MB_ICONERROR | MB_SETFOREGROUND);
  547.         return;
  548.     }
  549.     Sportsman S;
  550.     *left = 0;
  551.     while (getline(File_in, S.D.Name)) {
  552.         getline(File_in, S.D.Birthday);
  553.         getline(File_in, S.D.Sex);
  554.         getline(File_in, S.D.Weight);
  555.         getline(File_in, S.D.Rank);
  556.         getline(File_in, S.D.Team);
  557.         if (*left)
  558.             *right = Add(*right, S);
  559.         else {
  560.             *left = Add_first(S); *right = *left;
  561.         }
  562.         total_elements++;
  563.     }
  564.     File_in.close();
  565.     return;
  566. }
  567. //===============================================Write_File=================================================================================
  568. void Write_File(string File_name, Sportsman* left) {
  569.     ofstream File_out;
  570.     File_out.open(File_name);
  571.     if (!File_out) {
  572.         MessageBox(0, "Trere is no File!", "ERROR", MB_ICONERROR | MB_SETFOREGROUND);
  573.         return;
  574.     }
  575.     while (left) {
  576.         File_out << left->D.Name << endl;
  577.         File_out << left->D.Birthday << endl;
  578.         File_out << left->D.Sex << endl;
  579.         File_out << left->D.Weight << endl;
  580.         File_out << left->D.Rank << endl;
  581.         File_out << left->D.Team << endl;
  582.         left = left->next;
  583.     }
  584.     File_out.close();
  585.     return;
  586. }
  587. //===================================================Bin_File(Read)===================================================================================================================
  588. int Read_Bin_File(string filename, Sportsman** left, Sportsman** right) {
  589.     total_elements = 0;
  590.     ifstream file_read;
  591.     file_read.open(filename, ios::binary);
  592.  
  593.     if (!file_read) {
  594.         MessageBox(0, "There is no file!", "Error", MB_ICONERROR | MB_SETFOREGROUND);
  595.         return 1;
  596.     }
  597.     file_read.seekg(ios_base::beg);
  598.     Sportsman* S = new Sportsman;
  599.     S->next = NULL;
  600.     S->prev = NULL;
  601.     *left = 0;
  602.  
  603.     while (file_read.read((char*)&S->D, sizeof(S->D))) {
  604.         if (*left)
  605.             *right = Add(*right, *S);
  606.         else {
  607.             *left = Add_first(*S); *right = *left;
  608.         }
  609.         total_elements++;
  610.     }
  611.  
  612.     file_read.close();
  613.     return 0;
  614. }
  615. //===================================================Bin_File(Write)=================================================================================================
  616. void Write_Bin_File(string File_name, Sportsman* left) {
  617.     ofstream File_Bin_Write;
  618.     File_Bin_Write.open(File_name, ios::binary | ios::out);
  619.     if (!File_Bin_Write) {
  620.         MessageBox(0, "Trere is no File!", "ERROR", MB_ICONERROR | MB_SETFOREGROUND);
  621.         return;
  622.     }
  623.     while (left) {
  624.         File_Bin_Write.write((char*)&left->D, sizeof left->D);
  625.         left = left->next;
  626.     }
  627.     File_Bin_Write.close();
  628.     return;
  629. }
  630. //==================================================Search==========================================================================================
  631. void Search(Sportsman* left) {
  632.     cout << "Choose Information to Search" << endl;
  633.     string search_sm;
  634.     getline(cin, search_sm);
  635.     Sportsman* temp = left;
  636.     int count = 0;
  637.     cout << "====================================================================================" << endl;
  638.     while (temp) {
  639.         if (search_sm == temp->D.Name || search_sm == temp->D.Birthday || search_sm == temp->D.Sex || search_sm == temp->D.Weight || search_sm == temp->D.Team || search_sm == temp->D.Rank) {
  640.             Print(*temp);
  641.             count++;
  642.         }
  643.         temp = temp->next;
  644.     }
  645.     if (count == 0)
  646.         cout << "Nothing found" << endl;;
  647.     cout << "====================================================================================" << endl;
  648. }
  649. //====================================================Sort=================================================================================================
  650. void Sort(Sportsman* left, int sort_active) {
  651.     Sportsman* temp = left;
  652.     Sportsman* temp_i = left;
  653.     Sportsman* temp_j = left;
  654.     int Day_i = stoi(temp_i->D.Birthday.substr(0, 2));
  655.     int Month_i = stoi(temp_i->D.Birthday.substr(3, 2));
  656.     int Year_i = stoi(temp_i->D.Birthday.substr(6, 4));
  657.     int Day_j = stoi(temp_j->D.Birthday.substr(0, 2));
  658.     int Month_j = stoi(temp_j->D.Birthday.substr(3, 2));
  659.     int Year_j = stoi(temp_j->D.Birthday.substr(6, 4));
  660.     switch (sort_active) {
  661.     case 1:
  662.         for (Sportsman* temp_i = left; temp_i; temp_i = temp_i->next)
  663.         {
  664.             for (Sportsman* temp_j = temp_i; temp_j; temp_j = temp_j->next)
  665.                 if (temp_j->D.Name > temp_i->D.Name)
  666.                 {
  667.                     info tmp = temp_j->D;
  668.                     temp_j->D = temp_i->D;
  669.                     temp_i->D = tmp;
  670.                 }
  671.         }
  672.         break;
  673.     case 2:
  674.         for (Sportsman* temp_i = left; temp_i; temp_i = temp_i->next)
  675.         {
  676.             for (Sportsman* temp_j = temp_i; temp_j; temp_j = temp_j->next) {
  677.                 Day_i = stoi(temp_i->D.Birthday.substr(0, 2));
  678.                 Month_i = stoi(temp_i->D.Birthday.substr(3, 2));
  679.                 Year_i = stoi(temp_i->D.Birthday.substr(6, 4));
  680.                 Day_j = stoi(temp_j->D.Birthday.substr(0, 2));
  681.                 Month_j = stoi(temp_j->D.Birthday.substr(3, 2));
  682.                 Year_j = stoi(temp_j->D.Birthday.substr(6, 4));
  683.                 if (Year_j < Year_i)
  684.                 {
  685.                     info tmp = temp_j->D;
  686.                     temp_j->D = temp_i->D;
  687.                     temp_i->D = tmp;
  688.                 }
  689.                 else if ((Year_j == Year_i) && (Month_j < Month_i))
  690.                 {
  691.                     info tmp = temp_j->D;
  692.                     temp_j->D = temp_i->D;
  693.                     temp_i->D = tmp;
  694.                 }
  695.                 else if (((Year_j == Year_i) && (Month_j = Month_i)) && (Day_j < Day_i))
  696.                 {
  697.                     info tmp = temp_j->D;
  698.                     temp_j->D = temp_i->D;
  699.                     temp_i->D = tmp;
  700.                 }
  701.             }
  702.         }
  703.         break;
  704.     case 3:
  705.         for (Sportsman* temp_i = left; temp_i; temp_i = temp_i->next)
  706.         {
  707.             for (Sportsman* temp_j = temp_i; temp_j; temp_j = temp_j->next)
  708.                 if (temp_j->D.Sex > temp_i->D.Sex)
  709.                 {
  710.                     info tmp = temp_j->D;
  711.                     temp_j->D = temp_i->D;
  712.                     temp_i->D = tmp;
  713.                 }
  714.         }
  715.         break;
  716.     case 4:
  717.         for (Sportsman* temp_i = left; temp_i; temp_i = temp_i->next)
  718.         {
  719.             for (Sportsman* temp_j = temp_i; temp_j; temp_j = temp_j->next)
  720.                 if (stoi(temp_j->D.Weight) > stoi(temp_i->D.Weight))
  721.                 {
  722.                     info tmp = temp_j->D;
  723.                     temp_j->D = temp_i->D;
  724.                     temp_i->D = tmp;
  725.                 }
  726.         }
  727.         break;
  728.     case 5:
  729.         for (Sportsman* temp_i = left; temp_i; temp_i = temp_i->next)
  730.         {
  731.             for (Sportsman* temp_j = temp_i; temp_j; temp_j = temp_j->next)
  732.                 if (temp_j->D.Rank > temp_i->D.Rank)
  733.                 {
  734.                     info tmp = temp_j->D;
  735.                     temp_j->D = temp_i->D;
  736.                     temp_i->D = tmp;
  737.                 }
  738.         }
  739.         break;
  740.     case 6:
  741.         for (Sportsman* temp_i = left; temp_i; temp_i = temp_i->next)
  742.         {
  743.             for (Sportsman* temp_j = temp_i; temp_j; temp_j = temp_j->next)
  744.                 if (temp_j->D.Team > temp_i->D.Team)
  745.                 {
  746.                     info tmp = temp_j->D;
  747.                     temp_j->D = temp_i->D;
  748.                     temp_i->D = tmp;
  749.                 }
  750.         }
  751.         break;
  752.     }
  753. }
  754. //======================================================My_Function===============================================================================
  755. void My_Function(Sportsman* left) {
  756.     if (!left) {
  757.         MessageBox(0, "Trere Is Nothing In The List!", "ERROR", MB_ICONERROR | MB_SETFOREGROUND);
  758.         return;
  759.     }
  760.     Sportsman* temp = left;
  761.     int elements_in_total = 1;
  762.     while (temp) {
  763.         elements_in_total++;
  764.         temp = temp->next;
  765.     }
  766.     temp = left;
  767.     string* Mas_Teams = new string[elements_in_total];
  768.     Sort(left, 6);
  769.     string team_name = temp->D.Team;
  770.     Mas_Teams[0] = team_name;
  771.     int count_teams = 0;
  772.     while (temp) {
  773.         if (Mas_Teams[count_teams] != temp->D.Team) {
  774.             count_teams++;
  775.             Mas_Teams[count_teams] = temp->D.Team;
  776.         }
  777.         temp = temp->next;
  778.     }
  779.     int count = count_teams;
  780.     count_teams = 0;
  781.     Sort(left, 4);
  782.     int count_MF = 0;
  783.     temp = left;
  784.     int fl = 0;
  785.     while (temp) {
  786.         if (temp->D.Sex == "M") {
  787.             fl = 1;
  788.             break;
  789.         }
  790.         temp = temp->next;
  791.     }
  792.     temp = left;
  793.     if (fl == 0)
  794.         cout << "No Men" << endl;
  795.     else {
  796.         cout << "Most Man's Weight For Every Team" << endl;
  797.         cout << "==========================================================================================" << endl;
  798.         while (count_teams <= count) {
  799.             if (temp->D.Sex == "M" && count_MF < 5 && Mas_Teams[count_teams] == temp->D.Team) {
  800.                 Print(*temp);
  801.                 count_MF++;
  802.             }
  803.             temp = temp->next;
  804.             if (temp == NULL) {
  805.                 if (count_MF > 0) cout << "==========================================================================================" << endl;
  806.                 count_MF = 0;
  807.                 count_teams++;
  808.                 temp = left;
  809.  
  810.             }
  811.         }
  812.     }
  813.     cout << endl;
  814.     cout << endl;
  815.     cout << endl;
  816.     count_teams = 0;
  817.     Sort(left, 2);
  818.     count_MF = 0;
  819.     temp = left;
  820.     fl = 0;
  821.     while (temp) {
  822.         if (temp->D.Sex == "F") {
  823.             fl = 1;
  824.             break;
  825.         }
  826.         temp = temp->next;
  827.     }
  828.     temp = left;
  829.     if (fl == 0)
  830.         cout << "No Girls" << endl;
  831.     else {
  832.         cout << "The Oldest Girl For Every Team" << endl;
  833.         cout << "====================================================================================" << endl;
  834.         while (count_teams <= count) {
  835.             if (temp->D.Sex == "F" && count_MF < 5 && Mas_Teams[count_teams] == temp->D.Team) {
  836.                 Print(*temp);
  837.                 count_MF++;
  838.             }
  839.             temp = temp->next;
  840.             if (temp == NULL) {
  841.                 if (count_MF > 0)  cout << "====================================================================================" << endl;
  842.                 count_MF = 0;
  843.                 count_teams++;
  844.                 temp = left;
  845.  
  846.             }
  847.         }
  848.     }
  849.     system("pause");
  850.     delete[] Mas_Teams;
  851. }
  852. //==================================================================Delete_Number===================================================================================================================================================
  853. Sportsman* delete_By_Number(Sportsman * left) {
  854.     int  Number_To_Delete = 0;
  855.     Sportsman* temp;
  856.     Sportsman* buf;
  857.     if (!left) {
  858.         MessageBox(0, "It's Empty", "Warning", MB_ICONINFORMATION | MB_SETFOREGROUND);
  859.         return left;
  860.     }
  861.     cout << "Choose Number To Delete" << endl;
  862.     cin >> Number_To_Delete;
  863.  
  864.     if (total_elements < Number_To_Delete) {
  865.         MessageBox(0, "Trere is no Number Like That!", "ERROR", MB_ICONERROR | MB_SETFOREGROUND);
  866.         return left;
  867.     }
  868.     temp = left;
  869.     if (left->next == 0 && Number_To_Delete == 1) {
  870.         delete temp;
  871.         return 0;
  872.     }
  873.     int i = 1;
  874.     while (temp) {
  875.         if (i == Number_To_Delete) {
  876.             buf = temp->next;
  877.  
  878.            
  879.             if (temp->prev == 0) {
  880.                 buf->prev = 0;
  881.                 delete temp;
  882.                 return buf;
  883.             }
  884.  
  885.             if (buf != 0) buf->prev = temp->prev;
  886.  
  887.             buf = temp->prev;
  888.             buf->next = temp->next;
  889.             delete temp;
  890.             return left;
  891.         }
  892.         temp = temp->next;
  893.         i++;
  894.     }
  895.     MessageBox(0, "Error!", "Error", MB_ICONERROR | MB_SETFOREGROUND);
  896.     return left;
  897. }
  898. //=============================================================Edit==================================================================
  899. Sportsman* Edit(Sportsman* left, int Edit_Field) {
  900.     int Edit_Number = 0;
  901.     Sportsman* temp = left;
  902.     int i = 0;
  903.     if (!left) {
  904.         MessageBox(0, "It's Empty", "Warning", MB_ICONINFORMATION | MB_SETFOREGROUND);
  905.         return left;
  906.     }
  907.     cout << "Choose Number To Edit" << endl;
  908.     cin >> Edit_Number;
  909.  
  910.     if (total_elements < Edit_Number) {
  911.         MessageBox(0, "Trere is no Number Like That!", "ERROR", MB_ICONERROR | MB_SETFOREGROUND);
  912.         return left;
  913.     }
  914.     for (i = 1; i < Edit_Number; i++)
  915.         temp = temp->next;
  916.     cout << temp << endl;
  917.     boolean logic = 1;     
  918.     int max_length = 15;
  919.     switch (Edit_Field){
  920.  
  921.     case 1:
  922.         cout << "Choose Name(15 Symbols)" << endl;
  923.         do {
  924.             try {
  925.                 getline(cin, temp->D.Name);
  926.                 for (int i = 0; i < temp->D.Name.length(); i++)
  927.                     if ((temp->D.Name[i] >= '0' && temp->D.Name[i] <= '9') || temp->D.Name.length() > max_length)
  928.                         throw 1;
  929.                 break;
  930.             }
  931.             catch (int Y) {
  932.                 MessageBox(0, "Wrong Name", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  933.                 gotoxy(0, 1);
  934.                 clearRow(2);
  935.             }
  936.         } while (true);
  937.  
  938.         break;
  939.     case 2:
  940.  
  941.         break;
  942.     case 3:
  943.         cout << "Choose Sex (M/F)" << endl;
  944.         do {
  945.             cin.ignore();
  946.             getline(cin, temp->D.Sex);
  947.             cout << temp->D.Sex;
  948.             if ((temp->D.Sex == "M") || (temp->D.Sex == "F"))
  949.                 break;
  950.             else
  951.                 MessageBox(0, "There is no Sex like that!", "Warning", MB_ICONWARNING | MB_SETFOREGROUND);
  952.             gotoxy(0, 5);
  953.             clearRow(6);
  954.         } while (true);
  955.         break;
  956.     case 4:
  957.  
  958.         break;
  959.     case 5:
  960.  
  961.         break;
  962.     case 6:
  963.  
  964.         break;
  965.     }
  966.     cout << temp << endl;
  967.  
  968.  
  969.  
  970.  
  971.     system("pause");
  972.     return left;
  973. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement