From ad0b839a139b9348d4f392a00deff8ea76ae49c8 Mon Sep 17 00:00:00 2001 From: ChernyukVS Date: Tue, 16 Sep 2025 17:57:15 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 text.cpp diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..45fac48 --- /dev/null +++ b/text.cpp @@ -0,0 +1,38 @@ +#include "text.h" +#include + +using namespace std; + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH -3 -1; + +void +show_histogram_text(const vector& bins) +{ + size_t max_count = 0; + for (size_t count : bins) + { + if (count > max_count) + { + max_count = count; + } + } + + for (size_t count :bins){ + if (count < 10){ + cout << " " << count <<"|";} + else if (count < 100){ + cout <<" " << count << "|";} + if (count <1000){ + cout << count <<"|";} + size_t height; + if (max_count <= MAX_ASTERISK){ + height=count;} + else{ + height = static_cast(MAX_ASTERISK*(static_cast(count)/ max_count));} + + for (size_t j = 0; j< height ; j++){ + cout << "*";} + cout << endl; + } +}