Advertisement
treash

Untitled

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