From 6cfed337485d312b0f5d472786dd2de6c1b47247 Mon Sep 17 00:00:00 2001 From: "Nikolay (KrivobokovNS)" Date: Thu, 21 Aug 2025 13:47:25 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=D0=B0=20=D0=B3=D0=B8=D1=81=D1=82=D0=BE=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 text.cpp diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..7dca64c --- /dev/null +++ b/text.cpp @@ -0,0 +1,31 @@ +#include +#include +#include "text.h" + +void show_histogram_text(std::vector& bins, size_t bin_count) { + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + // Поиск максимального количесва оценок в одном столбце. + + size_t max_count = bins[0]; + + for (size_t i = 0; i < bin_count; i++) + { + if (bins[i] > max_count) + max_count = bins[i]; + } + +// Создание гистограммы по оценкам. + + size_t height; + + for (size_t i = 0; i < bin_count; i++) { + std::cout << bins[i] << "|"; + height = bins[i]; + if (max_count > MAX_ASTERISK) + height = MAX_ASTERISK * (static_cast(bins[i]) / max_count); + for (size_t j = 1; j <= height; j++) + std::cout << "*"; + std::cout << std::endl; + } +}