I need to implement the task:
Information system at the railway station contains information on the departure of long-distance trains. For each train, the train number, destination station, departure time are indicated. Implement a program that provides the initial data entry into the information system, outputs the entire list, enters the train number and displays all the data about this train, enters the name of the destination station and displays the data about all the trains going to this station. Required with two classes Train and Schedule. But I had a problem using STL libraries. During the search I need to have access to the fields of the train, but I do not know how to implement it
#include <string> #include <list> using namespace std; class Train { public: int number; string arrival_station; float time; //public: Train(); Train(int numb, string arr, float tim); }; class Timetable : public Train { private: Train train; list<Train>* trains; public: Timetable(); void add(Train); int find_number(number); //int find_station(); }; Implementations of methods (it is written crookedly and not perfectly :()
#include "pch.h" #include "Timetable.h" #include <iostream> using namespace std; Train::Train(int numb, string arr, float tim) { if (numb < 24.00) { number = numb; arrival_station = arr; time = tim; } else cout << "\nВремя введено некорректно"; } Train::Train() { } Timetable::Timetable() { } void Timetable::add(Train) { trains.push_back(train); } int Timetable::find_number(number) { list<Train>::const_iterator pos; pos = find(trains.begin(), trains.end(), number) cout << pos->number; }