Advertisement
treash

Untitled

Dec 26th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.33 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include<locale.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <conio.h>
  7. #include <string>
  8. #include <windows.h>
  9. #include <cstdio>
  10. #include <fstream>
  11. #include <iomanip>
  12.  
  13. using namespace std;
  14.  
  15. int index_admin; //фиксирут номер админа, под которым заходим в систему
  16. int index_user;   //фиксирует номер пользователя, под которым заходим в систему
  17. int flag_out=0;     //флаг для выхода из программы
  18. int kol_admin=0;    //количество зареганных админов в базе
  19. int kol_user=0;     //количество зареганных пользователей в базе
  20. int kol_people=0;    //количество участников в базе
  21.  
  22.                       //структура для паролей
  23. struct reg{
  24.     string login;
  25.     string password;
  26. } admin[10000],user[10000];
  27.  
  28.  
  29. struct inf{           //структура для участников
  30.     struct f_i_o{        //подструктура для ФИО
  31.         string family;
  32.         string name;
  33.         string otch;
  34.     } fio;
  35.    
  36.     string country;
  37.     string team;
  38.     int age;
  39.     double ttime;
  40.    
  41.  
  42. }  a[10000];      //в массиве а хранятся данные о участниках
  43.  
  44.  
  45. void Form_inf_people(){               //формируем файл inf_people.txt, в который записываем все данные о участниках
  46.     ofstream out1("inf_people.txt");   //открываем файл
  47.         for (int j=1; j<=kol_people; j++)
  48.             out1<<a[j].country<<" "<<a[j].team<<" "<<a[j].fio.family<<" "<<a[j].fio.name<<" "<<a[j].fio.otch<<" "<<a[j].age<<" "<<a[j].ttime<<endl; //выводим в файл инфу
  49.     out1.close();            //закрываем файл
  50.  
  51. }
  52.  
  53.                                
  54. void open_file(){               //выводим содержимое файла
  55.     struct inf mas;                    
  56.        
  57.     cout<<"Содержимое файла с данными о людях:"<<endl;
  58.     cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
  59.     ifstream in1("inf_people.txt");
  60.  
  61.         for (int i=1; i<=kol_people; i++){
  62.            
  63.             in1>>mas.country>>mas.team>>mas.fio.family>>mas.fio.name>>mas.fio.otch>>mas.age>>mas.ttime;
  64.             cout<<setw(15)<<left<<mas.country<<setw(15)<<left<<mas.team<<setw(15)<<left<<mas.fio.family<<setw(15)<<left<<mas.fio.name<<setw(15)<<left<<mas.fio.otch<<setw(15)<<left<<mas.age<<setw(15)<<left<<mas.ttime<<endl;
  65.         }  
  66.            
  67.     in1.close();
  68. }
  69.  
  70.                                      
  71. void new_people(){                   //добавляем нового участника
  72.     int n;
  73.     cout<<endl<<"Введите количество человек, которое вы хотите добавить: ";
  74.     cin>>n;
  75.  
  76.     for (int j=1; j<=n; j++){
  77.         kol_people++;
  78.        
  79.         cout<<"Введите страну"<<endl;
  80.         cin>>a[kol_people].country;
  81.        
  82.         cout<<"Введите название команды"<<endl;
  83.         cin>>a[kol_people].team;
  84.  
  85.         cout<<"Введите фамилию"<<endl;
  86.         cin>>a[kol_people].fio.family;
  87.        
  88.         cout<<"Введите имя"<<endl;
  89.         cin>>a[kol_people].fio.name;
  90.  
  91.         cout<<"Введите отчество"<<endl;
  92.         cin>>a[kol_people].fio.otch;
  93.        
  94.         cout<<"Введите возраст участника"<<endl;
  95.         cin>>a[kol_people].age;
  96.  
  97.         cout<<"Введите время заезда участника"<<endl;
  98.         cin>>a[kol_people].ttime;
  99.      
  100.         cout<<endl;
  101.     }
  102.  
  103.     Form_inf_people();
  104.  
  105.  
  106. }
  107.  
  108.  
  109. void del_people(){                   //удаляем участника по фамилии  
  110.     string ss;
  111.    
  112.     cout<<endl<<"Введите фамилию человека, которого хотите удалить"<<endl;
  113.     cin>>ss;
  114.  
  115.     int index=(-1);
  116.     for (int j=1; j<=kol_people; j++)
  117.         if (a[j].fio.family==ss) { index=j; break; }
  118.  
  119.     if (index==(-1)) cout<<"Такой фамилии в списке нет! Повторите свой выбор!"<<endl;
  120.         else {
  121.                 for (int j=index; j<=kol_people-1; j++)
  122.                     a[j]=a[j+1];
  123.                 kol_people--;
  124.                 cout<<"Человек успешно удалён"<<endl;
  125.              }
  126.     Form_inf_people();
  127. }
  128.  
  129.  
  130. void sort_people(){                            //сортируем данные по различным критериям
  131.     int r;
  132.     struct inf w;
  133.     cout<<"Выберите критерий сортировки:"<<endl;
  134.     cout<<"1) Сортировать по фамилии (по возрастанию)"<<endl;
  135.     cout<<"2) Сортировать по фамилии (по убыванию)"<<endl;
  136.     cout<<"3) Сортировать по времени заезда (по возрастанию)"<<endl;
  137.     cout<<"4) Сортировать по времени заезда (по убыванию)"<<endl;
  138.     cout<<"5) Сортировать по возрасту (по возрастанию)"<<endl;
  139.     cout<<"6) Сортировать по возрасту (по убыванию)"<<endl;
  140.     cout<<"Ваш выбор:"<<endl;
  141.    
  142.     cin>>r;
  143.     cout<<endl;
  144.    
  145.     int f=0;
  146.     while (1==1){
  147.         switch (r){
  148.             case 1:
  149.                 for (int ii=1; ii<=kol_people-1; ii++)
  150.                     for (int jj=1; jj<=kol_people-ii; jj++)
  151.                         if (a[jj].fio.family>=a[jj+1].fio.family) {
  152.                                                                     w=a[jj];
  153.                                                                     a[jj]=a[jj+1];
  154.                                                                     a[jj+1]=w;
  155.                                                                   }
  156.                 f=1;
  157.                 break;
  158.            
  159.             case 2:
  160.                 for (int ii=1; ii<=kol_people-1; ii++)
  161.                     for (int jj=1; jj<=kol_people-ii; jj++)
  162.                         if (a[jj].fio.family<=a[jj+1].fio.family) {
  163.                                                                     w=a[jj];
  164.                                                                     a[jj]=a[jj+1];
  165.                                                                     a[jj+1]=w;
  166.                                                                   }
  167.                 f=1;
  168.                 break;
  169.            
  170.             case 3:
  171.                 for (int ii=1; ii<=kol_people-1; ii++)
  172.                     for (int jj=1; jj<=kol_people-ii; jj++)
  173.                         if (a[jj].ttime>=a[jj+1].ttime) {
  174.                                                                 w=a[jj];
  175.                                                                 a[jj]=a[jj+1];
  176.                                                                 a[jj+1]=w;
  177.                                                             }
  178.                 f=1;
  179.                 break;
  180.            
  181.             case 4:
  182.                 for (int ii=1; ii<=kol_people-1; ii++)
  183.                     for (int jj=1; jj<=kol_people-ii; jj++)
  184.                         if (a[jj].ttime<=a[jj+1].ttime) {
  185.                                                                 w=a[jj];
  186.                                                                 a[jj]=a[jj+1];
  187.                                                                 a[jj+1]=w;
  188.                                                             }
  189.                 f=1;
  190.                 break;
  191.                  
  192.             case 5:
  193.                 for (int ii=1; ii<=kol_people-1; ii++)
  194.                     for (int jj=1; jj<=kol_people-ii; jj++)
  195.                         if (a[jj].age>=a[jj+1].age) {
  196.                                                                 w=a[jj];
  197.                                                                 a[jj]=a[jj+1];
  198.                                                                 a[jj+1]=w;
  199.                                                             }
  200.                 f=1;
  201.                 break;
  202.            
  203.             case 6:
  204.                 for (int ii=1; ii<=kol_people-1; ii++)
  205.                     for (int jj=1; jj<=kol_people-ii; jj++)
  206.                         if (a[jj].age<=a[jj+1].age) {
  207.                                                                 w=a[jj];
  208.                                                                 a[jj]=a[jj+1];
  209.                                                                 a[jj+1]=w;
  210.                                                             }
  211.                 f=1;
  212.                 break;
  213.            
  214.             default:
  215.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  216.         }
  217.  
  218.         if (f==1) break;                                                                   
  219.     }
  220.    
  221.     Form_inf_people();    //перезаписываем файл с инфой о участниках
  222.     open_file();         //выводим инфу
  223. }
  224.  
  225.  
  226. void editing_people(){     //редактируем данные по искомой фамилии
  227.     string s;
  228.     int f=0;
  229.  
  230.     cout<<endl<<"Введите фамилию для редактирования данных:"<<endl;
  231.     cin>>s;
  232.  
  233.     for (int t=1; t<=kol_people; t++)
  234.         if (a[t].fio.family==s) {
  235.                                     cout<<"Введите новые данные"<<endl;
  236.                                
  237.                                     cout<<"Введите страну"<<endl;
  238.                                     cin>>a[kol_people].country;
  239.        
  240.                                     cout<<"Введите название команды"<<endl;
  241.                                     cin>>a[kol_people].team;
  242.  
  243.                                     cout<<"Введите фамилию"<<endl;
  244.                                     cin>>a[kol_people].fio.family;
  245.        
  246.                                     cout<<"Введите имя"<<endl;
  247.                                     cin>>a[kol_people].fio.name;
  248.  
  249.                                     cout<<"Введите отчество"<<endl;
  250.                                     cin>>a[kol_people].fio.otch;
  251.        
  252.                                     cout<<"Введите возраст участника"<<endl;
  253.                                     cin>>a[kol_people].age;
  254.  
  255.                                     cout<<"Введите время заезда участника"<<endl;
  256.                                     cin>>a[kol_people].ttime;      
  257.  
  258.                                     f=1;
  259.                                     break;
  260.                                    
  261.                                 }
  262.         if (f==0) cout<<"Такой фамилии нет!!!"<<endl;
  263.             else {
  264.    
  265.                     Form_inf_people();
  266.                     open_file();
  267.                  } 
  268. }
  269.  
  270.  
  271.  
  272.  
  273. void search_people(){            //поиск данных по фамилии и их вывод
  274.     int tt;
  275.     string s;
  276.  
  277.     cout<<"Введите фамилию человека, данные о котором вы хотите получить"<<endl;
  278.     cin>>s;
  279.     cout<<endl;                                          
  280.     int ff=0;
  281.     for (int t=1; t<=kol_people; t++)
  282.         if (s==a[t].fio.family) {   if (tt==0)  cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
  283.                                     cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;
  284.                                     ff=1;
  285.                                     tt=1;
  286.                                     break;
  287.                                 }
  288.     if (ff==0) cout<<"Такой фамилии нет в базе!!!"<<endl;                                                              
  289. }
  290.  
  291.  
  292.  
  293. void filtration(){          //фильтрируем данные по различным критериям
  294.     int z, tt, age_x, age_y;
  295.     string country, team;
  296.     double time_x, time_y;
  297.  
  298.        
  299.     cout<<"Выберите критерий фильтрации"<<endl;
  300.     cout<<"1) По стране"<<endl;
  301.     cout<<"2) По названию команды"<<endl;
  302.     cout<<"3) По возрасту: меньше либо равному x, но большему либо равному y"<<endl;
  303.     cout<<"4) По времени заезда: меньше либо равному x, но большему либо равному y"<<endl;
  304.  
  305.     int f=0;
  306.  
  307.     while (1==1){
  308.         tt=0;
  309.         cout<<"Ваш выбор"<<endl;
  310.         cin>>z;
  311.         cout<<endl;
  312.  
  313.         switch(z){
  314.             case 1:
  315.                 cout<<"Введите страну: ";
  316.                 cin>>country;
  317.        
  318.                 for (int t=1; t<=kol_people; t++)
  319.                     if (a[t].country==country) {    
  320.                                                     if (tt==0)  cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
  321.                                                     cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;                                  
  322.                                                     tt=1;
  323.                                                }   
  324.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  325.                 f=1;
  326.                 break;
  327.        
  328.             case 2:            
  329.                 cout<<"Введите название команды: ";
  330.                 cin>>team;
  331.        
  332.                 for (int t=1; t<=kol_people; t++)
  333.                     if (a[t].team==team) {
  334.                                                 if (tt==0)  cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
  335.                                                 cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;                                  
  336.                                                 tt=1;
  337.                                           }
  338.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  339.                 f=1;
  340.                 break;
  341.        
  342.             case 3:
  343.                 cout<<"Введите x и y: "<<endl;
  344.                 cin>>age_x>>age_y;
  345.    
  346.                 for (int t=1; t<=kol_people; t++)
  347.                     if ( (a[t].age>=age_x) && (a[t].age<=age_y) ) {
  348.                                                                     if (tt==0)  cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
  349.                                                                     cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;                                  
  350.                                                                     tt=1;
  351.                                                                   }
  352.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  353.                 f=1;
  354.                 break;
  355.  
  356.             case 4:
  357.                 cout<<"Введите x и y: "<<endl;
  358.                 cin>>time_x>>time_y;
  359.    
  360.                 for (int t=1; t<=kol_people; t++)
  361.                     if ( (a[t].ttime>=time_x) && (a[t].ttime<=time_y) ) {
  362.                                                                         if (tt==0)  cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
  363.                                                                         cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;                                  
  364.                                                                         tt=1;
  365.                                                                       }
  366.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  367.                 f=1;
  368.                 break;
  369.  
  370.             default:
  371.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  372.         }
  373.     if (f==1) break;
  374.     }
  375. }
  376.  
  377. void editing_admin(){                       //смена логина\пароля админа
  378.     int q;
  379.     cout<<"1) Смена пароля"<<endl;  
  380.     cout<<"2) Смена логина"<<endl;
  381.    
  382.     int f=0;
  383.  
  384.     while (1==1){
  385.    
  386.         cout<<"Ваш выбор:"<<endl;
  387.         cin>>q;
  388.         cout<<endl;
  389.  
  390.         switch(q){
  391.             case 1:
  392.                 cout<<"Введите новый пароль:"<<endl;
  393.                 cin>>admin[index_admin].password;
  394.  
  395.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<admin[index_admin].login<<" "<<admin[index_admin].password<<endl;
  396.                 f=1;
  397.                 break; 
  398.             case 2:
  399.                 cout<<"Введите новый логин:"<<endl;
  400.                 cin>>admin[index_admin].login;
  401.  
  402.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<admin[index_admin].login<<" "<<admin[index_admin].password<<endl;
  403.                 f=1;
  404.                 break;
  405.                                                  
  406.             default:
  407.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  408.         }
  409.     if (f==1) break;
  410.     }
  411.  
  412.     ofstream out1("registry_admin.txt");
  413.  
  414.         for (int ij=1; ij<=kol_admin; ij++)
  415.             out1<<admin[ij].login<<" "<<admin[ij].password<<endl;
  416.    
  417.     out1.close();
  418. }
  419.  
  420. void Menu_Admin(){              //меню 2-го порядка
  421.     flag_out=0;
  422.     int x;
  423.     int d=0;
  424.  
  425.     while (d==0){
  426.    
  427.         cout<<"1) Просмотреть данные"<<endl;
  428.         cout<<"2) Добавить данные"<<endl;
  429.         cout<<"3) Удалить данные"<<endl;
  430.         cout<<"4) Сортировать данные"<<endl;
  431.         cout<<"5) Редактировать данные"<<endl;
  432.         cout<<"6) Поиск данных"<<endl;
  433.         cout<<"7) Фильтрация данных"<<endl;
  434.         cout<<"8) Смена пароля/логина"<<endl;
  435.         cout<<"9) Выход из программы"<<endl;
  436.         cout<<"10) Выход в Меню1"<<endl;
  437.         cout<<"Ваш выбор:"<<endl;
  438.  
  439.         cin>>x;
  440.         cout<<endl;
  441.  
  442.         switch(x){
  443.             case 1:
  444.                 open_file();
  445.                 break;
  446.             case 2:
  447.                 new_people();
  448.                 break;
  449.             case 3:
  450.                 del_people();
  451.                 break;         
  452.             case 4:
  453.                 sort_people();
  454.                 break;
  455.             case 5:
  456.                 editing_people();
  457.                 break;
  458.             case 6:
  459.                 search_people();
  460.                 break;
  461.  
  462.             case 7:
  463.                 filtration();
  464.                 break;
  465.             case 8:
  466.                 editing_admin();
  467.                 break;
  468.  
  469.             case 9:
  470.                 d=1;
  471.                 flag_out=1;
  472.                 break;
  473.  
  474.             case 10:
  475.                 d=1;
  476.                 break;
  477.             default:
  478.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  479.         }
  480.         cout<<endl;
  481.         if (d==1) break;
  482.     }
  483.  
  484. }
  485.  
  486.  
  487. void registry_admin(){            //регистрация нового админа
  488.  
  489.     kol_admin++;
  490.  
  491.     cout<<"Введиле логин:"<<endl;
  492.     cin>>admin[kol_admin].login;
  493.  
  494.     cout<<"Введите пароль:"<<endl;
  495.     cin>>admin[kol_admin].password;
  496.     cout<<endl;
  497.            
  498.     ofstream out1("registry_admin.txt");
  499.  
  500.         for (int i=1; i<=kol_admin; i++)
  501.             out1<<admin[i].login<<" "<<admin[i].password<<endl;
  502.    
  503.     out1.close();
  504. }
  505.  
  506.  
  507. void check_admin(){              //проверка верности логина и пароля при входе в систему
  508.     string llogin, ppassword;
  509.     cout<<"Введиле логин:"<<endl;
  510.     cin>>llogin;
  511.  
  512.     cout<<"Введите пароль:"<<endl;
  513.     cin>>ppassword;
  514.  
  515.     int flag=0;
  516.     for (int i=1; i<=kol_admin; i++)
  517.         if ( (admin[i].login==llogin) && (admin[i].password==ppassword) ) { flag=1; index_admin=i; }
  518.                                                                                    
  519.     if (flag==0) cout<<"Вы ввели неверные логин и пароль"<<endl;
  520.         else {cout<<"Пароль и логин верны, вы отправляетесь в Меню2"<<endl; Menu_Admin();}
  521.  
  522.     cout<<endl;
  523.  
  524. }
  525.      
  526.  
  527. void code_Admin(){           //меню входа/регистрации в систему под админом
  528.     int x;
  529.     int d=0;
  530.  
  531.     while (d==0){
  532.         if (flag_out==1) break;
  533.         cout<<"1) Вход"<<endl;
  534.         cout<<"2) Регистрация"<<endl;
  535.         cout<<"3) Выход в Меню1"<<endl;
  536.         cout<<"Ваш выбор:"<<endl;
  537.  
  538.         cin>>x;
  539.         cout<<endl;
  540.  
  541.         switch(x){
  542.             case 1:
  543.                 d=1;
  544.                 check_admin();
  545.                 break;
  546.             case 2:
  547.                 d=1;
  548.                 registry_admin();
  549.                 break;
  550.             case 3:
  551.                 d=1;
  552.                 break;
  553.             default:
  554.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  555.         }
  556.         cout<<endl;
  557.         if (d==1) break;
  558.     }
  559.  
  560. }
  561.  
  562.  
  563. void editing_user(){                      //смена пароля\логина пользователя
  564.     int q;
  565.     cout<<"1) Смена пароля"<<endl;  
  566.     cout<<"2) Смена логина"<<endl;
  567.    
  568.     int f=0;
  569.  
  570.     while (1==1){
  571.    
  572.         cout<<"Ваш выбор:"<<endl;
  573.         cin>>q;
  574.         cout<<endl;
  575.  
  576.         switch(q){
  577.             case 1:
  578.                 cout<<"Введите новый пароль:"<<endl;
  579.                 cin>>user[index_user].password;
  580.  
  581.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<user[index_user].login<<" "<<user[index_user].password<<endl;
  582.                 f=1;
  583.                 break; 
  584.             case 2:
  585.                 cout<<"Введите новый логин:"<<endl;
  586.                 cin>>user[index_user].login;
  587.  
  588.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<user[index_user].login<<" "<<user[index_user].password<<endl;
  589.                 f=1;
  590.                 break;
  591.                                                  
  592.             default:
  593.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  594.         }
  595.     if (f==1) break;
  596.     }
  597.  
  598.     ofstream out1("registry_user.txt");
  599.  
  600.         for (int ij=1; ij<=kol_user; ij++)
  601.             out1<<user[ij].login<<" "<<user[ij].password<<endl;
  602.    
  603.     out1.close();
  604. }
  605.  
  606.  
  607.  
  608. void Menu_User(){     //меню 2-го порядка для пользователя
  609.     flag_out=0;
  610.     int x;
  611.     int d=0;
  612.  
  613.     while (d==0){
  614.    
  615.         cout<<"1) Просмотреть данные"<<endl;
  616.         cout<<"2) Сортировать данные"<<endl;
  617.         cout<<"3) Поиск данных"<<endl;
  618.         cout<<"4) Фильтрация данных"<<endl;
  619.         cout<<"5) Смена пароля/логина"<<endl;
  620.         cout<<"6) Выход из программы"<<endl;
  621.         cout<<"7) Выход в Меню1"<<endl;
  622.         cout<<"Ваш выбор:"<<endl;
  623.  
  624.         cin>>x;
  625.         cout<<endl;
  626.  
  627.         switch(x){
  628.             case 1:
  629.                 open_file();
  630.                 break;
  631.             case 2:
  632.                 sort_people();
  633.                 break;
  634.             case 3:
  635.                 search_people();
  636.                 break;
  637.  
  638.             case 4:
  639.                 filtration();
  640.                 break;
  641.             case 5:
  642.                 editing_user();
  643.                 break;
  644.  
  645.             case 6:
  646.                 d=1;
  647.                 flag_out=1;
  648.                 break;
  649.  
  650.             case 7:
  651.                 d=1;
  652.                 break;
  653.             default:
  654.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  655.         }
  656.         cout<<endl;
  657.         if (d==1) break;
  658.     }
  659.  
  660. }
  661.  
  662.  
  663.  
  664.  
  665. void registry_user(){       //регистрация нового пользователя
  666.  
  667.     kol_user++;
  668.  
  669.     cout<<"Введиле логин:"<<endl;
  670.     cin>>user[kol_user].login;
  671.  
  672.     cout<<"Введите пароль:"<<endl;
  673.     cin>>user[kol_user].password;
  674.     cout<<endl;
  675.            
  676.     ofstream out1("registry_user.txt");
  677.  
  678.         for (int i=1; i<=kol_user; i++)
  679.             out1<<user[i].login<<" "<<user[i].password<<endl;
  680.    
  681.     out1.close();
  682. }
  683.  
  684. void check_user(){              //проверка правильности введённых логина и пароля
  685.     string llogin, ppassword;
  686.     cout<<"Введиле логин:"<<endl;
  687.     cin>>llogin;
  688.  
  689.     cout<<"Введите пароль:"<<endl;
  690.     cin>>ppassword;
  691.  
  692.     int flag=0;
  693.     for (int i=1; i<=kol_user; i++)
  694.         if ( (user[i].login==llogin) && (user[i].password==ppassword) ) { flag=1; index_user=i; }
  695.                                                                                    
  696.     if (flag==0) cout<<"Вы ввели неверные логин и пароль"<<endl;
  697.         else {cout<<"Пароль и логин верны, вы отправляетесь в Меню2"<<endl; Menu_User();}
  698.  
  699.     cout<<endl;
  700.  
  701. }
  702.  
  703.  
  704. void code_User(){                    //меню входа\регистрации в сисиему для пользователя
  705.     int x;
  706.     int d=0;
  707.  
  708.     while (d==0){
  709.         if (flag_out==1) break;
  710.         cout<<"1) Вход"<<endl;
  711.         cout<<"2) Регистрация"<<endl;
  712.         cout<<"3) Выход в Меню1"<<endl;
  713.         cout<<"Ваш выбор:"<<endl;
  714.  
  715.         cin>>x;
  716.         cout<<endl;
  717.  
  718.         switch(x){
  719.             case 1:
  720.                 d=1;
  721.                 check_user();
  722.                 break;
  723.             case 2:
  724.                 d=1;
  725.                 registry_user();
  726.                 break;
  727.             case 3:
  728.                 d=1;
  729.                 break;
  730.             default:
  731.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  732.         }
  733.         cout<<endl;
  734.         if (d==1) break;
  735.     }
  736.  
  737. }
  738.  
  739.  
  740.  
  741.  
  742. int main()
  743. {
  744.     bool Done = 0;
  745.     int t;
  746.    
  747.    
  748.     system("color F0");
  749.     setlocale(LC_ALL, "Russian");
  750.    
  751.     while(Done!=1){
  752.         if (flag_out==1) break;
  753.         cout<<"Меню 1"<<endl;
  754.         cout<<"1) Администратор"<<endl;
  755.         cout<<"2) Пользователь"<<endl;
  756.         cout<<"3) Выход"<<endl;
  757.         cout<<"Ваш выбор:"<<endl;
  758.  
  759.         cin>>t;
  760.         cout<<endl;
  761.  
  762.         switch(t){
  763.             case 1:
  764.                 code_Admin();
  765.                 break;
  766.             case 2:
  767.                 code_User();
  768.                 break;
  769.             case 3:
  770.                 Done=1;
  771.                 break;
  772.             default:
  773.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  774.         }
  775.         cout<<endl;    
  776.     }
  777. return 0;
  778. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement