Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct Trains
  6. {
  7. string city;
  8. int number;
  9. int hours;
  10. int minutes;
  11.  
  12. void input()
  13. {
  14. cout « "=================================================" « endl;
  15. cout « "Пункт назначения: "; cin » city;
  16. cout « "Номер поезда: "; cin » number;
  17. cout « "Время отправления." « endl;
  18. cout « "Часы: "; cin » hours;
  19. cout « "Минуты: "; cin » minutes;
  20. cout « "=================================================" « endl;
  21. }
  22.  
  23. void output()
  24. {
  25. cout « "________________________________________________" « endl;
  26. cout « "Пункт назначения: " « city « endl;
  27. cout « "Номер поезда: " « number « endl;
  28. cout « "Время отправления." « endl;
  29. cout « "Часы: " « hours « endl;
  30. cout « "Минуты: " « minutes « endl;
  31. cout « "________________________________________________" « endl;
  32. }
  33. };
  34.  
  35. int main()
  36. {
  37. const int n = 3;
  38.  
  39. setlocale(LC_ALL, "Russian");
  40. Trains a[n];
  41. Trains tmp;
  42. int i, j;
  43. bool flag = false;
  44. int search;
  45.  
  46.  
  47. cout « "Ввод информации" « endl;
  48. for ( i = 0; i < n; i++)
  49. {
  50. cout « "Поезд " « endl;
  51. a[i].input();
  52. }
  53.  
  54. for ( i = 0; i < n-1; i++)
  55. {
  56. for ( j = 0; j < n-1-i; j++)
  57. {
  58. if (a[j].number > a[j + 1].number)
  59. {
  60. tmp = a[j];
  61. a[j] = a[j+1];
  62. a[j+1] = tmp;
  63. }
  64. }
  65.  
  66. }
  67. cout « "Отсортированный список:\n";
  68.  
  69. for ( i = 0; i < 3; i++){
  70. a[i].output();
  71.  
  72. }
  73.  
  74.  
  75. int input = 1;
  76. while (input)
  77. {
  78. flag = false;
  79.  
  80. cout « "\nВведите номер поезда: ";
  81. cin » search;
  82. for (i = 0; i < 3; i++)
  83. {
  84. if (a[i].number == search)
  85. {
  86. flag = true;
  87. a[i].output();
  88. }
  89.  
  90. }
  91.  
  92. if (!flag)
  93. cout « "Извините, по вашему запросу ничего не найдено." « endl;
  94. cout « "\nХотите продолжить поиск (1 -да, 0 -нет) ";
  95. cin » input;
  96.  
  97. }
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement