Advertisement
Guest User

Поезд(23,11)

a guest
Nov 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 KB | None | 0 0
  1. // ConsoleApplication12.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. # include <iostream>
  6. # include <stdlib.h>
  7. # include <string.h>
  8. # include <time.h>
  9. #include<windows.h>
  10.  
  11. using namespace std;
  12.  
  13. struct TRAIN
  14. {
  15.     char item[15];
  16.     int number;
  17.     char time[6];
  18. };
  19.  
  20. void zap(TRAIN *tr, int count)
  21. {
  22.  
  23.  
  24.     cout << "------ Информация для " << count++ << " поезда ----------------------" << endl;
  25.     cout << "Введите пункт назначения : ";
  26.     cin >> tr->item;
  27.     //cin.getline(tr->item,15);  Почему так не получается прочитать информацию??
  28.     cout << "Введите номер поезда : ";
  29.     cin >> tr->number;
  30.     cout << "Введите время прибытия  ( ЧЧ : ММ )  : ";
  31.     cin >> tr->time;
  32.     cout << "----------------------------" << endl;
  33.  
  34. }
  35.  
  36. void sort(TRAIN *tr, int &n)
  37. {
  38.     TRAIN p;
  39.  
  40.     cout << "Сортирока по номерам поездов произведена" << endl;
  41.  
  42.     //for(int i=0; i<n; i++)
  43.     for (int j = 0; j<(n - 1); j++)
  44.     {
  45.         if (tr[j].number>tr[j + 1].number)
  46.         {
  47.             p = *(tr + j);
  48.             *(tr + j) = *(tr + j + 1);
  49.             *(tr + j + 1) = p;
  50.         }
  51.  
  52.     }
  53. }
  54.  
  55.  
  56. void main()
  57. {
  58.     TRAIN inf[2];
  59.     int count;
  60.     int n = 2;
  61.     int i;
  62.     int nom;
  63.     bool flag = false;
  64.     char otv[3];
  65.     char otv1[3];
  66.     char zn[3] = "да";
  67.  
  68.     setlocale(LC_ALL, "rus");
  69.     SetConsoleCP(1251);
  70.     SetConsoleOutputCP(1251);
  71.     count = 0;
  72.  
  73.     while (count<n)
  74.         zap(&inf[count++], count);
  75.  
  76.     cout << "Введите номер поезда для которого вы хотите получить информацию : ";
  77.     cin >> nom;
  78.     for (i = 0; i<2; i++)
  79.  
  80.     if (inf[i].number == nom)
  81.     {
  82.         flag = true;
  83.         cout << "----------------------------" << endl;
  84.         cout << "Пункт назнаения : " << inf[i].item << endl;
  85.         cout << "Номер поезда : " << inf[i].number << endl;
  86.         cout << "Время прибытия : " << inf[i].time << endl;
  87.         cout << "----------------------------" << endl;
  88.     }
  89.     if (flag == false)
  90.         cout << "Информации по вашему запросу не найдено!" << endl;
  91.     cout << "Хотите ли произвести сортировку базы по номеру поезда\nда/нет" << endl;
  92.     cin >> otv;
  93.     if (*otv == *zn)
  94.     {
  95.         sort(inf, n);
  96.         for (i = 0; i<2; i++)
  97.         {
  98.             cout << "----------------------------" << endl;
  99.             cout << "Пункт назнаения : " << inf[i].item << endl;
  100.             cout << "Номер поезда : " << inf[i].number << endl;
  101.             cout << "Время прибытия : " << inf[i].time << endl;
  102.             cout << "----------------------------" << endl;
  103.         }
  104.     }
  105.     else
  106.         cout << "Вывести на информацию о поездах?" << endl;
  107.     cin >> otv1;
  108.  
  109.  
  110.     if (*otv1 == *zn)
  111.     for (i = 0; i<2; i++)
  112.     {
  113.         cout << "----------------------------" << endl;
  114.         cout << "Пункт назнаения : " << inf[i].item << endl;
  115.         cout << "Номер поезда : " << inf[i].number << endl;
  116.         cout << "Время прибытия : " << inf[i].time << endl;
  117.         cout << "----------------------------" << endl;
  118.     }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement