Advertisement
Guest User

Untitled

a guest
Jan 8th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.92 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[t].country;
  239.        
  240.                                     cout<<"Введите название команды"<<endl;
  241.                                     cin>>a[t].team;
  242.  
  243.                                     cout<<"Введите фамилию"<<endl;
  244.                                     cin>>a[t].fio.family;
  245.        
  246.                                     cout<<"Введите имя"<<endl;
  247.                                     cin>>a[t].fio.name;
  248.  
  249.                                     cout<<"Введите отчество"<<endl;
  250.                                     cin>>a[t].fio.otch;
  251.        
  252.                                     cout<<"Введите возраст участника"<<endl;
  253.                                     cin>>a[t].age;
  254.  
  255.                                     cout<<"Введите время заезда участника"<<endl;
  256.                                     cin>>a[t].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. void search_people(){            
  272.     int tt;
  273.     string s;
  274.  
  275.     cout<<"Введите фамилию человека, данные о котором вы хотите получить"<<endl;
  276.     cin>>s;
  277.     cout<<endl;                                          
  278.     int ff=0;
  279.     for (int t=1; t<=kol_people; t++)
  280.         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;
  281.                                     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;
  282.                                     ff=1;
  283.                                     tt=1;
  284.                                     break;
  285.                                 }
  286.     if (ff==0) cout<<"Такой фамилии нет в базе!!!"<<endl;                                                              
  287. }
  288.  
  289.  
  290.  
  291. void filtration(){          //фильтрируем данные по различным критериям
  292.     int z, tt, age_x, age_y;
  293.     string country, team;
  294.     double time_x, time_y;
  295.  
  296.        
  297.     cout<<"Выберите критерий фильтрации"<<endl;
  298.     cout<<"1) По стране"<<endl;
  299.     cout<<"2) По названию команды"<<endl;
  300.     cout<<"3) По возрасту: меньше либо равному x, но большему либо равному y"<<endl;
  301.     cout<<"4) По времени заезда: меньше либо равному x, но большему либо равному y"<<endl;
  302.  
  303.     int f=0;
  304.  
  305.     while (1==1){
  306.         tt=0;
  307.         cout<<"Ваш выбор"<<endl;
  308.         cin>>z;
  309.         cout<<endl;
  310.  
  311.         switch(z){
  312.             case 1:
  313.                 cout<<"Введите страну: ";
  314.                 cin>>country;
  315.        
  316.                 for (int t=1; t<=kol_people; t++)
  317.                     if (a[t].country==country) {    
  318.                                                     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;
  319.                                                     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;                                  
  320.                                                     tt=1;
  321.                                                }   
  322.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  323.                 f=1;
  324.                 break;
  325.        
  326.             case 2:            
  327.                 cout<<"Введите название команды: ";
  328.                 cin>>team;
  329.        
  330.                 for (int t=1; t<=kol_people; t++)
  331.                     if (a[t].team==team) {
  332.                                                 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;
  333.                                                 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;                                  
  334.                                                 tt=1;
  335.                                           }
  336.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  337.                 f=1;
  338.                 break;
  339.        
  340.             case 3:
  341.                 cout<<"Введите x и y: "<<endl;
  342.                 cin>>age_x>>age_y;
  343.    
  344.                 for (int t=1; t<=kol_people; t++)
  345.                     if ( (a[t].age>=age_x) && (a[t].age<=age_y) ) {
  346.                                                                     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;
  347.                                                                     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;                                  
  348.                                                                     tt=1;
  349.                                                                   }
  350.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  351.                 f=1;
  352.                 break;
  353.  
  354.             case 4:
  355.                 cout<<"Введите x и y: "<<endl;
  356.                 cin>>time_x>>time_y;
  357.    
  358.                 for (int t=1; t<=kol_people; t++)
  359.                     if ( (a[t].ttime>=time_x) && (a[t].ttime<=time_y) ) {
  360.                                                                         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;
  361.                                                                         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;                                  
  362.                                                                         tt=1;
  363.                                                                       }
  364.                 if (tt==0) cout<<"Таких людей нет!"<<endl;
  365.                 f=1;
  366.                 break;
  367.  
  368.             default:
  369.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  370.         }
  371.     if (f==1) break;
  372.     }
  373. }
  374.  
  375. void editing_admin(){                       //смена логина\пароля админа
  376.     int q;
  377.     cout<<"1) Смена пароля"<<endl;  
  378.     cout<<"2) Смена логина"<<endl;
  379.    
  380.     int f=0;
  381.  
  382.     while (1==1){
  383.    
  384.         cout<<"Ваш выбор:"<<endl;
  385.         cin>>q;
  386.         cout<<endl;
  387.  
  388.         switch(q){
  389.             case 1:
  390.                 cout<<"Введите новый пароль:"<<endl;
  391.                 cin>>admin[index_admin].password;
  392.  
  393.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<admin[index_admin].login<<" "<<admin[index_admin].password<<endl;
  394.                 f=1;
  395.                 break; 
  396.             case 2:
  397.                 cout<<"Введите новый логин:"<<endl;
  398.                 cin>>admin[index_admin].login;
  399.  
  400.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<admin[index_admin].login<<" "<<admin[index_admin].password<<endl;
  401.                 f=1;
  402.                 break;
  403.                                                  
  404.             default:
  405.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  406.         }
  407.     if (f==1) break;
  408.     }
  409.  
  410.     ofstream out1("registry_admin.txt");
  411.  
  412.         for (int ij=1; ij<=kol_admin; ij++)
  413.             out1<<admin[ij].login<<" "<<admin[ij].password<<endl;
  414.    
  415.     out1.close();
  416. }
  417.  
  418. void Menu_Admin(){              
  419.     flag_out=0;
  420.     int x;
  421.     int d=0;
  422.  
  423.     while (d==0){
  424.    
  425.         cout<<"1) Просмотреть данные"<<endl;
  426.         cout<<"2) Добавить данные"<<endl;
  427.         cout<<"3) Удалить данные"<<endl;
  428.         cout<<"4) Сортировать данные"<<endl;
  429.         cout<<"5) Редактировать данные"<<endl;
  430.         cout<<"6) Поиск данных"<<endl;
  431.         cout<<"7) Фильтрация данных"<<endl;
  432.         cout<<"8) Смена пароля/логина"<<endl;
  433.         cout<<"9) Выход из программы"<<endl;
  434.         cout<<"10) Выход в Меню1"<<endl;
  435.         cout<<"Ваш выбор:"<<endl;
  436.  
  437.         cin>>x;
  438.         cout<<endl;
  439.  
  440.         switch(x){
  441.             case 1:
  442.                 open_file();
  443.                 break;
  444.             case 2:
  445.                 new_people();
  446.                 break;
  447.             case 3:
  448.                 del_people();
  449.                 break;         
  450.             case 4:
  451.                 sort_people();
  452.                 break;
  453.             case 5:
  454.                 editing_people();
  455.                 break;
  456.             case 6:
  457.                 search_people();
  458.                 break;
  459.  
  460.             case 7:
  461.                 filtration();
  462.                 break;
  463.             case 8:
  464.                 editing_admin();
  465.                 break;
  466.  
  467.             case 9:
  468.                 d=1;
  469.                 flag_out=1;
  470.                 break;
  471.  
  472.             case 10:
  473.                 d=1;
  474.                 break;
  475.             default:
  476.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  477.         }
  478.         cout<<endl;
  479.         if (d==1) break;
  480.     }
  481.  
  482. }
  483.  
  484.  
  485. void registry_admin(){            //регистрация нового админа
  486.  
  487.     kol_admin++;
  488.  
  489.     cout<<"Введиле логин:"<<endl;
  490.     cin>>admin[kol_admin].login;
  491.  
  492.     cout<<"Введите пароль:"<<endl;
  493.     cin>>admin[kol_admin].password;
  494.     cout<<endl;
  495.            
  496.     ofstream out1("registry_admin.txt");
  497.  
  498.         for (int i=1; i<=kol_admin; i++)
  499.             out1<<admin[i].login<<" "<<admin[i].password<<endl;
  500.    
  501.     out1.close();
  502. }
  503.  
  504.  
  505. void check_admin(){              //проверка верности логина и пароля при входе в систему
  506.     string llogin, ppassword;
  507.     cout<<"Введиле логин:"<<endl;
  508.     cin>>llogin;
  509.  
  510.     cout<<"Введите пароль:"<<endl;
  511.     cin>>ppassword;
  512.  
  513.     int flag=0;
  514.     for (int i=1; i<=kol_admin; i++)
  515.         if ( (admin[i].login==llogin) && (admin[i].password==ppassword) ) { flag=1; index_admin=i; }
  516.                                                                                    
  517.     if (flag==0) cout<<"Вы ввели неверные логин и пароль"<<endl;
  518.         else {cout<<"Пароль и логин верны, вы отправляетесь в Меню2"<<endl; Menu_Admin();}
  519.  
  520.     cout<<endl;
  521.  
  522. }
  523.      
  524.  
  525. void code_Admin(){           //меню входа/регистрации в систему под админом
  526.     int x;
  527.     int d=0;
  528.  
  529.     while (d==0){
  530.         if (flag_out==1) break;
  531.         cout<<"1) Вход"<<endl;
  532.         cout<<"2) Регистрация"<<endl;
  533.         cout<<"3) Выход в Меню1"<<endl;
  534.         cout<<"Ваш выбор:"<<endl;
  535.  
  536.         cin>>x;
  537.         cout<<endl;
  538.  
  539.         switch(x){
  540.             case 1:
  541.                 d=1;
  542.                 check_admin();
  543.                 break;
  544.             case 2:
  545.                 d=1;
  546.                 registry_admin();
  547.                 break;
  548.             case 3:
  549.                 d=1;
  550.                 break;
  551.             default:
  552.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  553.         }
  554.         cout<<endl;
  555.         if (d==1) break;
  556.     }
  557.  
  558. }
  559.  
  560.  
  561. void editing_user(){                      //смена пароля\логина пользователя
  562.     int q;
  563.     cout<<"1) Смена пароля"<<endl;  
  564.     cout<<"2) Смена логина"<<endl;
  565.    
  566.     int f=0;
  567.  
  568.     while (1==1){
  569.    
  570.         cout<<"Ваш выбор:"<<endl;
  571.         cin>>q;
  572.         cout<<endl;
  573.  
  574.         switch(q){
  575.             case 1:
  576.                 cout<<"Введите новый пароль:"<<endl;
  577.                 cin>>user[index_user].password;
  578.  
  579.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<user[index_user].login<<" "<<user[index_user].password<<endl;
  580.                 f=1;
  581.                 break; 
  582.             case 2:
  583.                 cout<<"Введите новый логин:"<<endl;
  584.                 cin>>user[index_user].login;
  585.  
  586.                 cout<<endl<<"Ваш логин и пароль:"<<endl<<user[index_user].login<<" "<<user[index_user].password<<endl;
  587.                 f=1;
  588.                 break;
  589.                                                  
  590.             default:
  591.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  592.         }
  593.     if (f==1) break;
  594.     }
  595.  
  596.     ofstream out1("registry_user.txt");
  597.  
  598.         for (int ij=1; ij<=kol_user; ij++)
  599.             out1<<user[ij].login<<" "<<user[ij].password<<endl;
  600.    
  601.     out1.close();
  602. }
  603.  
  604.  
  605.  
  606. void Menu_User(){     //меню 2-го порядка для пользователя
  607.     flag_out=0;
  608.     int x;
  609.     int d=0;
  610.  
  611.     while (d==0){
  612.    
  613.         cout<<"1) Просмотреть данные"<<endl;
  614.         cout<<"2) Сортировать данные"<<endl;
  615.         cout<<"3) Поиск данных"<<endl;
  616.         cout<<"4) Фильтрация данных"<<endl;
  617.         cout<<"5) Смена пароля/логина"<<endl;
  618.         cout<<"6) Выход из программы"<<endl;
  619.         cout<<"7) Выход в Меню1"<<endl;
  620.         cout<<"Ваш выбор:"<<endl;
  621.  
  622.         cin>>x;
  623.         cout<<endl;
  624.  
  625.         switch(x){
  626.             case 1:
  627.                 open_file();
  628.                 break;
  629.             case 2:
  630.                 sort_people();
  631.                 break;
  632.             case 3:
  633.                 search_people();
  634.                 break;
  635.  
  636.             case 4:
  637.                 filtration();
  638.                 break;
  639.             case 5:
  640.                 editing_user();
  641.                 break;
  642.  
  643.             case 6:
  644.                 d=1;
  645.                 flag_out=1;
  646.                 break;
  647.  
  648.             case 7:
  649.                 d=1;
  650.                 break;
  651.             default:
  652.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  653.         }
  654.         cout<<endl;
  655.         if (d==1) break;
  656.     }
  657.  
  658. }
  659.  
  660. void registry_user(){       //регистрация нового пользователя
  661.  
  662.     kol_user++;
  663.  
  664.     cout<<"Введиле логин:"<<endl;
  665.     cin>>user[kol_user].login;
  666.  
  667.     cout<<"Введите пароль:"<<endl;
  668.     cin>>user[kol_user].password;
  669.     cout<<endl;
  670.            
  671.     ofstream out1("registry_user.txt");
  672.  
  673.         for (int i=1; i<=kol_user; i++)
  674.             out1<<user[i].login<<" "<<user[i].password<<endl;
  675.    
  676.     out1.close();
  677. }
  678.  
  679. void check_user(){              //проверка правильности введённых логина и пароля
  680.     string llogin, ppassword;
  681.     cout<<"Введиле логин:"<<endl;
  682.     cin>>llogin;
  683.  
  684.     cout<<"Введите пароль:"<<endl;
  685.     cin>>ppassword;
  686.  
  687.     int flag=0;
  688.     for (int i=1; i<=kol_user; i++)
  689.         if ( (user[i].login==llogin) && (user[i].password==ppassword) ) { flag=1; index_user=i; }
  690.                                                                                    
  691.     if (flag==0) cout<<"Вы ввели неверные логин и пароль"<<endl;
  692.         else {cout<<"Пароль и логин верны, вы отправляетесь в Меню2"<<endl; Menu_User();}
  693.  
  694.     cout<<endl;
  695.  
  696. }
  697.  
  698.  
  699. void code_User(){                    //меню входа\регистрации в сисиему для пользователя
  700.     int x;
  701.     int d=0;
  702.  
  703.     while (d==0){
  704.         if (flag_out==1) break;
  705.         cout<<"1) Вход"<<endl;
  706.         cout<<"2) Регистрация"<<endl;
  707.         cout<<"3) Выход в Меню1"<<endl;
  708.         cout<<"Ваш выбор:"<<endl;
  709.  
  710.         cin>>x;
  711.         cout<<endl;
  712.  
  713.         switch(x){
  714.             case 1:
  715.                 d=1;
  716.                 check_user();
  717.                 break;
  718.             case 2:
  719.                 d=1;
  720.                 registry_user();
  721.                 break;
  722.             case 3:
  723.                 d=1;
  724.                 break;
  725.             default:
  726.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  727.         }
  728.         cout<<endl;
  729.         if (d==1) break;
  730.     }
  731.  
  732. }
  733.  
  734.  
  735. int main()
  736. {
  737.     bool Done = 0;
  738.     int t;
  739.    
  740.    
  741.     system("color F0");
  742.     setlocale(LC_ALL, "Russian");
  743.    
  744.     while(Done!=1){
  745.         if (flag_out==1) break;
  746.         cout<<"Меню 1"<<endl;
  747.         cout<<"1) Администратор"<<endl;
  748.         cout<<"2) Пользователь"<<endl;
  749.         cout<<"3) Выход"<<endl;
  750.         cout<<"Ваш выбор:"<<endl;
  751.  
  752.         cin>>t;
  753.         cout<<endl;
  754.  
  755.         switch(t){
  756.             case 1:
  757.                 code_Admin();
  758.                 break;
  759.             case 2:
  760.                 code_User();
  761.                 break;
  762.             case 3:
  763.                 Done=1;
  764.                 break;
  765.             default:
  766.                 cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
  767.         }
  768.         cout<<endl;    
  769.     }
  770.  
  771. return 0;
  772. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement