From b3300dcec7ed9574d6c184240e8bc0b013565593 Mon Sep 17 00:00:00 2001 From: "PARZIVAL (BreganIM)" Date: Mon, 14 Apr 2025 00:48:04 +0300 Subject: [PATCH] =?UTF-8?q?code:=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B3=D0=B8=D1=81=D1=82=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- laba01upd3.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/laba01upd3.cpp b/laba01upd3.cpp index c765b10..09debdb 100644 --- a/laba01upd3.cpp +++ b/laba01upd3.cpp @@ -64,6 +64,34 @@ vector make_histogram(const vector& numbers, size_t bin_count) { return bins; } +void show_histogram_text(const vector& bins, size_t screen_width = SCREEN_WIDTH) { + const size_t MAX_ASTERISK = screen_width - 3 - 1; + size_t max_count = bins[0]; + for (size_t count : bins) { + if (count > max_count) + max_count = count; + } + for (size_t j = 0; j < bins.size(); j++) { + if (bins[j] < 100) + cout << " "; + if (bins[j] < 10) + cout << " "; + cout << bins[j] << "|"; + + size_t height = 0; + if (max_count > MAX_ASTERISK) { + height = static_cast(static_cast(bins[j]) / max_count * MAX_ASTERISK); + } + else { + height = bins[j]; + } + for (size_t i = 0; i < height; i++) { + cout << "*"; + } + cout << endl; + } +} + int main() { size_t number_count;