/
ArtT
/
Netology
Обзор
Документация
Войти
/
ArtT
/
Netology
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Part5/Task_5_2_2/Task_5_2_2.cpp
89 строк
2 KB
ArtT
Добавил задание 5_2
29 май 2026, 19:44
29 май 2026, 19:44
d180f20
Код
Авторство
О чём код?
#include <iostream> #include <thread> #include <vector> #include <mutex> #include <string> #include <iomanip> #include <chrono> #include "Timer.h" using namespace std; enum Color : int { BLACK = 0, DARK_BLUE = 1, DARK_GREEN = 2, DARK_CYAN = 3, DARK_RED = 4, PURPLE = 5, DARK_YELLOW = 6, LIGHT_GREY = 7, DARK_GREY = 8, BLUE = 9, GREEN = 10, CYAN = 11, RED = 12, PINK = 13, YELLOW = 14, WHITE = 15 }; const int COLORS[] = { CYAN, GREEN, YELLOW, PINK, BLUE, RED }; constexpr int CALC_STEPS = 40; constexpr int BAR_WIDTH = 20; mutex mtx; void drawRowProgress(int idx, int total) { int color = COLORS[idx % 6]; this_thread::sleep_for(150ms); for (int step = 0; step <= CALC_STEPS; step++) { this_thread::sleep_for(100ms); auto start = chrono::high_resolution_clock::now(); int filled = (step * BAR_WIDTH) / CALC_STEPS; lock_guard<mutex> lk(mtx); consol_parameter::SetPosition(0, idx + 1); // строка потока consol_parameter::SetColor(WHITE, BLACK); cout << setw(2) << this_thread::get_id() << " "; //Заполненная часть consol_parameter::SetColor(color, BLACK); for (int i = 0; i < filled; ++i) cout << (char)0xDB; //Пустая часть consol_parameter::SetColor(DARK_GREY, BLACK); for (int i = filled; i < BAR_WIDTH; ++i) cout << (char)0xB0; consol_parameter::SetColor(WHITE, BLACK); cout << "| "; if (step != CALC_STEPS) { consol_parameter::SetColor(LIGHT_GREY, BLACK); } else { auto end = chrono::high_resolution_clock::now(); chrono::duration<double, milli> time = end - start; consol_parameter::SetColor(GREEN, BLACK); cout << to_string(time.count()); } consol_parameter::SetColor(WHITE, BLACK); cout << flush; } } int main() { vector<thread> TV; for (int i = 1; i <= 5; i++) { TV.push_back(thread(drawRowProgress, i, 5)); } for (auto& t : TV) { t.join(); } consol_parameter::SetPosition(0, 6); return EXIT_SUCCESS; }