C/C++

Надо написать программу на с++ СРОЧНО!!!!! ПОЖАЛУЙСТА

Ключ: время вылета. Сортировка выбором.
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
struct Time {
short hour;
short minute;
Time() : hour(0), minute(0) {}
Time(const short hour, const short minute) : hour(hour), minute(minute) {}
string time()const {
string t = hour < ten ? "0" : "";
t += to_string(hour) + ":" + (minute < ten ? "0" : "");
t += to_string(minute);
return t;
}
private:
static const auto ten = 10;
static const auto sixty = 60;
friend bool operator<(const Time& a, const Time& b) {
return a.hour * sixty + a.minute < b.hour * sixty + b.minute;
}
friend ostream& operator<<(ostream& out, const Time& t) {
return out << t.time();
}
};
struct Flight {
Time time;
string destination;
private:
friend bool operator<(const Flight& a, const Flight& b) {
return a.time < b.time;
}
};
class Schedule {
public:
void add(const Flight& flight) {
table.push_back(flight);
}
void add(Flight&& flight) {
table.emplace_back(move(flight));
}
void sort() {
for (int i = 0; i < table.size() - 1; ++i) {
int m = i;
for (int j = i + 1; j < table.size(); ++j) {
if (table[j] < table[m]) {
m = j;
}
}
swap(table[i], table[m]);
}
}
void show()const {
for (auto& [time, destination] : table) {
cout << time << ' ' << destination << '\n';
}
}
private:
vector<Flight> table;
};
int main() {
system("chcp 1251 > nul");
Schedule schedule;
schedule.add({ {23, 12}, "Москва" });
schedule.add({ {17, 8}, "Лондон" });
schedule.add({ {3, 15}, "Минск" });
schedule.add({ {14, 42}, "Варшава" });
schedule.add({ {11, 9}, "Мадрид" });
schedule.add({ {1, 3}, "Пекин" });
schedule.add({ {17, 58}, "Токио" });
schedule.sort();
schedule.show();
system("pause > nul");
}
Алекс
Алекс
89 449
Лучший ответ
Osken Moldaliev мальчик хочет в shedule.add({{0,0},"Тамбов"}) но не летят туда сегодня самолеты и не едут даже поезда