Advertisement
sneyzi

Untitled

Jun 22nd, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. struct marsh{
  7.     char start[100];
  8.     char end[100];
  9.     unsigned int nuber;
  10. };
  11.  
  12. void inputMarsh(marsh &a){
  13.     setlocale(0, "");
  14.     cout << "Введите начальный пункт: ";
  15.     cin >> a.start;
  16.     cout << "Введите конечный пункт: ";
  17.     cin >> a.end;
  18.     cout << "Введите номер маршрута: ";
  19.     cin >> a.nuber;
  20. }
  21.  
  22. void sort(marsh* a, int n){
  23.     for (int i = 0; i < n -1; i++){
  24.         for (int j = 0; j < n - i; j++){
  25.             if (a[j].nuber > a[j+1].nuber)
  26.                 swap(a[j], a[j+1]);
  27.         }
  28.     }
  29. }
  30.  
  31. void outputMarsh(marsh &a){
  32.     cout << "Номер маршрута: " << a.nuber << endl;
  33.     cout << "Начальный пункт: " << a.start << endl;
  34.     cout << "Конечный пункт: "<< a.end << endl;
  35.     cout << endl << endl;
  36. }
  37.  
  38. void searchInform(marsh* a, int n){
  39.     while(1){
  40.         char tmp[100];
  41.         const char _exit[] = "-1\0";
  42.         cout << "Для выхода из программы наберите -1" << endl << endl;
  43.         cout << "Введите пункт, информация о котором вас интересует: ";
  44.         cin >> tmp;
  45.         bool _check = false;
  46.         for (int i = 0; i < n; i++){
  47.             if (!strcmp(a[i].end, tmp) || !strcmp(a[i].start, tmp)){
  48.                 outputMarsh(a[i]);
  49.                 _check = true;
  50.             }
  51.         }
  52.         if (!strcmp(tmp, _exit))
  53.             exit(1);
  54.         if (!_check){
  55.             cout << "Ничего не найдено" << endl;
  56.         }
  57.     }
  58. }
  59.  
  60. int main()
  61. {
  62.     static const char n = 3; //кол-во элементов массива
  63.  
  64.     marsh marsh_array[n];
  65.  
  66.     for (int i = 0; i < n; i++)
  67.         inputMarsh(marsh_array[i]);
  68.  
  69.     sort(marsh_array, n);
  70.     searchInform(marsh_array, n);
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement