Skip to content

Instantly share code, notes, and snippets.

@bilinin
Created February 28, 2017 16:07
Show Gist options
  • Save bilinin/4a3e21959927bd2b506a14d4b3a2df4c to your computer and use it in GitHub Desktop.
Save bilinin/4a3e21959927bd2b506a14d4b3a2df4c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
struct Ttime{
int hour;
int minute;
};
class Train{
public:
// Конструктор
Train(string Destination, string Number, Ttime Time,int Common, int Compartment, int ReservedSeat){
set_destination(Destination);
set_number(Number);
set_time(Time);
set_common(Common);
set_compartment(Compartment);
set_reserved_seat(ReservedSeat);
}
// Сеттеры
void set_destination(string destination){
Destination = destination;
}
void set_number(string number){
Number = number;
}
void set_time(Ttime time){
Time = time;
}
void set_common(int common){
Common = common;
}
void set_compartment(int compartment){
Compartment = compartment;
}
void set_reserved_seat(int reserved_sat){
ReservedSeat = reserved_sat;
}
// Геттеры
string get_destination(){
return Destination;
}
string get_number(){
return Number;
}
Ttime get_time(){
return Time;
}
int get_common(){
return Common;
}
int get_compartment(){
return Compartment;
}
int get_reserved_seat() {
return ReservedSeat;
}
// other
void print_all_data(){
cout << Destination << " " << Number << " " << Time.hour << ":" << Time.minute <<" " << Common << " "
<< " " << Compartment << " " << ReservedSeat << endl;
}
private:
/* 6. Train: Пункт назначения, Номер поезда, Время отправления,
Число общих мест, Купейных, Плацкартных. Создать массив объек-
тов. */
string Destination,
Number;
Ttime Time;
int Common,
Compartment,
ReservedSeat;
};
void show_destination(vector <Train> Trains, string destination){
cout << "\n\n Trains to " << destination << endl;
int size = Trains.size();
for (int i = 0;i<size; i++){
if(Trains[i].get_destination() == destination){
Trains[i].print_all_data();
}
}
}
void show_destination_hour(vector <Train> Trains, string destination, int hour){
cout << "\n\n Trains to " << destination << " after " << hour << endl;
int size = Trains.size();
for (int i = 0;i<size; i++){
if((Trains[i].get_destination() == destination) && (Trains[i].get_time().hour > hour)){
Trains[i].print_all_data();
}
}
}
void show_destination_common(vector <Train> Trains, string destination){
cout << "\n\n Common seats to " << destination << endl;
int size = Trains.size();
for (int i = 0;i<size; i++){
if((Trains[i].get_destination() == destination) && (Trains[i].get_common() > 0)){
Trains[i].print_all_data();
}
}
}
int main() {
vector <Train> Trains;
Trains.push_back(Train("Moskow", "777", {10,20}, 100, 50, 60));
Trains.push_back(Train("Moskow", "777", {20,20}, 110, 60, 70));
Trains.push_back(Train("Novosibirsk", "234", {15,40}, 110, 50, 40));
Trains.push_back(Train("Barnayl", "563", {20,10}, 0, 70, 30));
Trains.push_back(Train("Barnayl", "563", {20,10}, 10, 70, 30));
show_destination(Trains, "Novosibirsk");
show_destination_hour(Trains, "Moskow", 11 );
show_destination_common(Trains, "Barnayl");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment