#include "pch.h"
#include <iostream>
using namespace std;
const int NUM_OF_TRAIN = 25;
const int MAX = 80;
struct Time
{
int hour, minutes;
};
struct Train
{
char direction[MAX];
Time arival, departure;
};
void random(Train trains[])
{
const char * directions[NUM_OF_TRAIN][100] = { "baranovichi-zhitomir",
"minsk-simferopol",
"kaliningrad-adler",
"minsk-odessa",
"minsk-simferopol",
"minsk–kalinkovichi–gomel",
"minsk-gomel",
"minsk-adler",
"minsk-mineralnye",
"minsk-anapa",
"minsk-feodosiya",
"minsk-kiev",
"minsk-simferopol",
"baranovichi-mariupol",
"minsk-evpatoriya",
"simferopol-minsk",
"grodno-gomel",
"simferopol-minsk",
"gomel-minsk",
"minsk–kalinkovichi",
"mariupol-minsk",
"minsk-kishinev",
"baranovichi-zhitomir",
"minsk-simferopol",
"kaliningrad-adler" };
for (int i = 0; i < NUM_OF_TRAIN; i++)
{
trains[i].arival.hour = 0 + rand() % 23;
cout << "Time arrival: " << trains[i].arival.hour << " hour, ";
trains[i].arival.minutes = 0 + rand() % 59;
cout << trains[i].arival.minutes << " minutes" << endl;
trains[i].departure.hour = 0 + rand() % 23;
cout << "Time departure: " << trains[i].departure.hour << " hour, ";
trains[i].departure.minutes = 0 + rand() % 59;
cout << trains[i].departure.minutes << " minutes" << endl;
strcpy_s(trains[i].direction, *directions[i]);
cout << trains[i].direction << endl << "-----------------------------------------------" << endl;
}
};
int hour_to_minutes(Time T)
{
return (T.hour * 60) + T.minutes;
};
int main()
{
Train trains[NUM_OF_TRAIN];
Time time_user;
int hour_to_minutes(Time);
random(trains);
cout << "Enter time (h, m)" << endl;
cin >> time_user.hour >> time_user.minutes;
for (int i = 0; i < NUM_OF_TRAIN; i++)
{
if (hour_to_minutes(trains[i].arival) > hour_to_minutes(trains[i].departure))
{
if ((hour_to_minutes(time_user) >= hour_to_minutes(trains[i].arival) && hour_to_minutes(time_user) <= 1439) || (hour_to_minutes(time_user) >= 0 && hour_to_minutes(time_user) <= hour_to_minutes(trains[i].departure)))
{
if (hour_to_minutes(trains[i].departure) >= hour_to_minutes(time_user))
{
cout << "remaining time: " << (1439 - hour_to_minutes(trains[i].arival) + hour_to_minutes(time_user)) / 60 << " hour " << (1439 - hour_to_minutes(trains[i].arival) + hour_to_minutes(time_user)) % 60 << " minutes" << endl;
cout << "Direction: " << trains[i].direction << endl << "------------------------------------------" << endl;
}
if (hour_to_minutes(time_user) >= hour_to_minutes(trains[i].arival))
{
cout << "remaining time: " << (hour_to_minutes(time_user) - hour_to_minutes(trains[i].arival)) / 60 << " hour " << (hour_to_minutes(time_user) - hour_to_minutes(trains[i].arival)) % 60 << " minutes" << endl;
cout << "Direction: " << trains[i].direction << endl << "------------------------------------------" << endl;
}
}
}
if (hour_to_minutes(trains[i].arival) < hour_to_minutes(trains[i].departure))
{
if ((hour_to_minutes(time_user) > hour_to_minutes(trains[i].arival)) && (hour_to_minutes(time_user) < hour_to_minutes(trains[i].departure)))
{
cout << "remaining time: " << ((hour_to_minutes(trains[i].departure) - hour_to_minutes(time_user)) / 60) << " hour " << ((hour_to_minutes(trains[i].departure) - hour_to_minutes(time_user) % 60)) << " minutes" << endl;
cout << "Direction: " << trains[i].direction << endl << "------------------------------------------" << endl;
}
}
}
system("pause");
return 0;
};