/
NeonBite
/
cpp-oop-2
Обзор
Документация
Войти
/
NeonBite
/
cpp-oop-2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
timeee.cpp
120 строк
2 KB
Winnie-the-Pooh2019
initial commit
17 фев 2026, 09:06
17 фев 2026, 09:06
81e6801
Код
Авторство
О чём код?
#include <iostream> #include "timeee.h" using std::cout; using std::endl; Time::Time() { hours = new int(0); minutes = new int(0); seconds = new int(0); } Time::Time(int hours, int minutes, int seconds) { this->hours = new int(hours); this->minutes = new int(minutes); this->seconds = new int(seconds); } Time::~Time() { delete hours; delete minutes; delete seconds; hours = nullptr; minutes = nullptr; seconds = nullptr; } void Time::add_seconds(int s) { *seconds += s; normalize(); } void Time::normalize() { *minutes += *seconds / 60; *seconds %= 60; if (*seconds < 0) { *minutes -= 1; *seconds += 60; } *hours += *minutes / 60; *minutes %= 60; if (*minutes < 0) { *hours -= 1; *minutes += 60; } *hours %= 24; if (*hours < 0) { *hours += 24; } } string Time::to_string() { stringstream ss; ss << *hours << " : " << *minutes << " : " << *seconds; return ss.str(); } void Time::set_hours(int hours) { *this->hours = hours; } void Time::set_minutes(int minutes) { *this->minutes = minutes; } void Time::set_seconds(int seconds) { *this->seconds = seconds; } int Time::get_hours() const { return *hours; } int Time::get_minutes() const { return *minutes; } int Time::get_seconds() const { return *seconds; } vector<Time> sort_ascending_hours(vector<Time>& arr) { vector<Time> sorted = arr; for (int i = 0; i < sorted.size(); i++) { for (int j = i; j < sorted.size(); j++) { if (sorted[i].get_hours() > sorted[j].get_hours()) { Time t = sorted[i]; sorted[i] = sorted[j]; sorted[j] = t; } } } return sorted; } vector<Time> sort_descending_seconds(vector<Time>& arr) { vector<Time> sorted = arr; for (int i = 0; i < sorted.size(); i++) { for (int j = i; j < sorted.size(); j++) { if (sorted[i].get_seconds() < sorted[j].get_seconds()) { Time t = sorted[i]; sorted[i] = sorted[j]; sorted[j] = t; } } } return sorted; }