Advertisement
Guest User

Untitled

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