Ответ:
Исходник прикреплю в закреп, в двух форматах на всякий!!
Объяснение:
#include
#include
#include
using namespace std;
class Time {
public:
Time()
: m_hours(0), m_minutes(0) {
//TODO
}
Time(short hours, short minutes)
: m_hours(hours), m_minutes(minutes) {
//TODO
}
Time operator-(const Time& time) {
Time tempTime;
tempTime.m_minutes = this->m_minutes - time.m_minutes;
if (tempTime.m_minutes < 0) {
tempTime.m_minutes += 60;
}
tempTime.m_hours = this->m_hours - time.m_hours;
if (tempTime.m_hours < 0) {
tempTime.m_hours += 23;
}
return tempTime;
}
friend std::ostream& operator<<(std::ostream& os, const Time& time);</p>
friend std::istream& operator>>(std::istream& is, Time& time);
short m_hours;
short m_minutes;
};
std::ostream& operator<<(std::ostream& os, const Time& time) {</p>
if (time.m_hours < 10) {
os<< "0";</p>
}
os<< time.m_hours << ":";</p>
if (time.m_minutes < 10) {
os<< "0";</p>
}
os<< time.m_minutes;</p>
return os;
}
std::istream& operator>>(std::istream& is, Time& time) {
char delim{ ':' };
is>> time.m_hours >> delim >> time.m_minutes;
if (time.m_hours > 23) {
time.m_hours %= 24;
}
if (time.m_minutes > 59) {
time.m_minutes %= 60;
}
return is;
}
class train
{
public:
string punkt;
int trainNumber;
Time startTime;
train(string punkt1, int trainNumber1, Time startTime1)
{
punkt = punkt1;
trainNumber = trainNumber1;
startTime = startTime1;
}
};
int main()
{
train* arrayOfTrain[5];
for (int i = 0; i < 5; i++)
{
string punkt;
int trainNumber;
Time startTime;
cin >> punkt;
cin >> trainNumber;
cin >> startTime;
arrayOfTrain[i] = new train(punkt, trainNumber, startTime);
}
//Сортировка
for (int i = 0; i < 5 - 1; i++)
for (int j = i + 1; j < 5; j++) {
if (strcmp(arrayOfTrain[i]->punkt.c_str(), arrayOfTrain[j]->punkt.c_str()) > 0)
{
swap(arrayOfTrain[i], arrayOfTrain[j]);
}
}
for (int i = 0; i < 5 - 1; i++)
for (int j = i + 1; j < 5; j++) {
if (strcmp(arrayOfTrain[i]->punkt.c_str(), arrayOfTrain[j]->punkt.c_str()) == 0)
{
if (arrayOfTrain[i]->startTime.m_hours > arrayOfTrain[j] -> startTime.m_hours)
swap(arrayOfTrain[i], arrayOfTrain[j]);
if (arrayOfTrain[i]->startTime.m_hours == arrayOfTrain[j] -> startTime.m_hours)
if (arrayOfTrain[i] -> startTime.m_minutes > arrayOfTrain[j] -> startTime.m_minutes)
swap(arrayOfTrain[i], arrayOfTrain[j]);
}
}
for (int i = 0; i < 5; i++)
{
cout << arrayOfTrain[i]->punkt << " " << arrayOfTrain[i]->trainNumber << " " << arrayOfTrain[i]->startTime << endl;</p>
}
system("pause");
return 0;
}
Скачать вложение Текст (TXT)