From 643a7c7c787e0d71faf1cf9ba879c621725071e8 Mon Sep 17 00:00:00 2001 From: ShinkarenkoVA Date: Mon, 22 Apr 2024 03:09:25 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=84=D0=B0=D0=B9=D0=BB=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 text.cpp diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..86b58fd --- /dev/null +++ b/text.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include "text.h" +using namespace std; +void +show_histogram_text(const vector bins, size_t bin_count){ + const size_t MAX_ELEMENT = 76; + double max_count = bins[0]; + for (size_t j=0; j < bin_count; j++){ + if (bins[j] > max_count) { + max_count = bins[j]; + } + } + vector height(bin_count); + for (size_t j=0; j < bin_count; j++){ + height[j] = MAX_ELEMENT * (bins[j]/max_count); + } + + if (max_count > MAX_ELEMENT){ + for (size_t j=0; j < bin_count; j++) + { + if (bins[j] < 100) { + cout << " "; + if (bins[j] < 10){ + cout << " "; + } + } + cout << bins[j] << "|"; + + for (size_t i=0; i < height[j]; i++){ + cout << "*"; + } + cout << endl; + } + } + else { + for (size_t j=0; j < bin_count; j++) + { + if (bins[j] < 100) { + cout << " "; + if (bins[j] < 10){ + cout << " "; + } + } + cout << bins[j] << "|"; + + for (size_t i=0; i < bins[j];i++){ + cout << "*"; + } + cout << endl; + } + } +}