From fce6d4daeb39d45ec2b078dd0f44499228f17bd4 Mon Sep 17 00:00:00 2001 From: MatusSV Date: Mon, 13 May 2024 08:45:13 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B2=D1=8B=D0=BD=D0=BE=D1=81=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=87=D0=B0=D1=82=D0=B8=20=D1=82=D0=B5=D0=BA=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=B9=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=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 28 +--------------------------- text.cpp | 31 +++++++++++++++++++++++++++++++ text.h | 9 +++++++++ 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 text.cpp create mode 100644 text.h diff --git a/main.cpp b/main.cpp index 4c74947..3d3fbe9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include "histogram.h" +#include "text.h" using namespace std; @@ -29,33 +30,6 @@ input_data() { return in; } -void -show_histogram_text(const 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 = 0; - - for (size_t s = 0; s < bin_count; s++) - { - if (bins[s] > max_count) - { - max_count = bins[s]; - } - } - - for (size_t bin : bins) - { - if (bin < 100) cout << " "; - if (bin < 10) cout << " "; - cout << bin; - cout << "|"; - size_t height = MAX_ASTERISK * (static_cast(bin) / max_count); - if (max_count <= MAX_ASTERISK) height = bin; - for (size_t i = 0; i < height; i++) cout << "*"; - cout << endl; - } -} - int main() { Input in = input_data(); diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..aceb930 --- /dev/null +++ b/text.cpp @@ -0,0 +1,31 @@ +#include +#include "text.h" + +using namespace std; + +void +show_histogram_text(const 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 = 0; + + for (size_t s = 0; s < bin_count; s++) + { + if (bins[s] > max_count) + { + max_count = bins[s]; + } + } + + for (size_t bin : bins) + { + if (bin < 100) cout << " "; + if (bin < 10) cout << " "; + cout << bin; + cout << "|"; + size_t height = MAX_ASTERISK * (static_cast(bin) / max_count); + if (max_count <= MAX_ASTERISK) height = bin; + for (size_t i = 0; i < height; i++) cout << "*"; + cout << endl; + } +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..5c6df4d --- /dev/null +++ b/text.h @@ -0,0 +1,9 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED + +#include + +void +show_histogram_text(const std::vector& bins, size_t& bin_count); + +#endif // TEXT_H_INCLUDED