#include <iostream>
#include <string>
#include <set>
#include <stdlib.h>
using namespace std;
class Train {
private:
int num;
string endPoint;
string time;
public:
Train(int num1, string endPoint1, string time1) {
num = num1;
endPoint = endPoint1;
time = time1;
}
void info() {
cout << "Поезд #" << num << ", " <<
"Пункт назначения: " << endPoint << ", " <<
"Время отправления: " << time << endl;
}
int getId() {
return num;
}
string getEndpoint() {
return endPoint;
}
};
set<Train*> list;
void mainMenu();
void inputMenu() {
int choice;
bool n = true;
cout << "Ввод данных о поездах." << endl;
while (n) {
int subChoice;
int num;
string endPoint;
string time;
cout << "Введите номер поезда: ";
cin >> num;
cout << endl << "Введите станцию назначения: ";
cin >> endPoint;
cin.ignore();
cout << endl << "Введите время отправления: ";
cin >> time;
cin.ignore();
Train *newTrain = new Train(num, endPoint, time);
list.insert(newTrain);
cout << "Ввести ещё? 1 - Да, 2 - Нет" << endl;
cin >> subChoice;
if (subChoice == 2) {
n = false;
break;
}
}
mainMenu();
}
void findAll() {
cout << "========" << endl;
cout << "Информация о поездах:" << endl;
for (auto it = list.begin(); it != list.end(); ++it) {
(*it)->info();
}
cout << "========" << endl;
mainMenu();
}
void findByIdMenu() {
cout << "========" << endl;
int id;
cout << "Введите номер поезда: ";
cin >> id;
for (auto it = list.begin(); it != list.end(); ++it) {
if ((*it)->getId() == id) {
(*it)->info();
}
}
cout << "========" << endl;
mainMenu();
}
void findByEndpoint() {
cout << "========" << endl;
string endPoint;
cout << "Введите пункт назначения: ";
cin >> endPoint;
cin.ignore();
for (auto it = list.begin(); it != list.end(); ++it) {
if ((*it)->getEndpoint() == endPoint) {
(*it)->info();
}
}
cout << "========" << endl;
mainMenu();
}
void mainMenu() {
int choice;
cout << "Главное меню:" << endl;
cout << "1. Ввод данных" << endl;
cout << "2. Сведения по всем поездам" << endl;
cout << "3. Сведения по номеру поезда" << endl;
cout << "4. Сведения по пункту назначения" << endl;
cout << "0. Выход" << endl;
cin >> choice;
switch (choice) {
default:
cout << "Выбран неверный пункт" << endl;
break;
case 1:
inputMenu();
break;
case 2:
findAll();
break;
case 3:
findByIdMenu();
break;
case 4:
findByEndpoint();
break;
case 0:
exit(0);
break;
}
}
int main() {
mainMenu();
}