From 8a1329f4a7688f1bdbcec327371ad42b4cffdcb3 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 19 Apr 2024 22:35:42 +0300 Subject: [PATCH] =?UTF-8?q?build:=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20show=5Fhistogram?= =?UTF-8?q?=5Ftext()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 57 +------------------------------------------------------- text.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ text.h | 12 ++++++++++++ 3 files changed, 68 insertions(+), 56 deletions(-) create mode 100644 text.cpp create mode 100644 text.h diff --git a/main.cpp b/main.cpp index 58e6ee2..b1eefd9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,7 @@ #include #include #include "histogram.h" - -const size_t SCREEN_WIDTH = 80; -const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; +#include "text.h" using namespace std; @@ -32,59 +30,6 @@ input_data(){ return in; } -void -show_histogram_text(vector& bins){ - - size_t max_count = 0; - for (size_t x: bins) { - if (x > max_count) { - max_count = x; - } - } - - if (max_count > MAX_ASTERISK) { - for (size_t count: bins) { - size_t height = MAX_ASTERISK * (static_cast(count) / max_count); - if (count < 10) { - cout << " " << count << "|"; - } - else if (count >= 100) { - cout << count << "|"; - } - - else { - cout << " " << count << "|"; - } - - for (size_t i = 0; i < height; i++) { - cout << "*"; - } - cout << "\n"; - } - } - - else { - for (size_t x: bins) { - if (x < 10) { - cout << " " << x << "|"; - } - else if (x >= 100) { - cout << x << "|"; - } - - else { - cout << " " << x << "|"; - } - - for (size_t i = 0; i < x; i++) { - cout << "*"; - } - cout << "\n"; - } - } - -} - int main() { diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..1a3dbc2 --- /dev/null +++ b/text.cpp @@ -0,0 +1,55 @@ +#include "text.h" +#include + +void +show_histogram_text(std::vector& bins){ + + size_t max_count = 0; + for (size_t x: bins) { + if (x > max_count) { + max_count = x; + } + } + + if (max_count > MAX_ASTERISK) { + for (size_t count: bins) { + size_t height = MAX_ASTERISK * (static_cast(count) / max_count); + if (count < 10) { + std::cout << " " << count << "|"; + } + else if (count >= 100) { + std::cout << count << "|"; + } + + else { + std::cout << " " << count << "|"; + } + + for (size_t i = 0; i < height; i++) { + std::cout << "*"; + } + std::cout << "\n"; + } + } + + else { + for (size_t x: bins) { + if (x < 10) { + std::cout << " " << x << "|"; + } + else if (x >= 100) { + std::cout << x << "|"; + } + + else { + std::cout << " " << x << "|"; + } + + for (size_t i = 0; i < x; i++) { + std::cout << "*"; + } + std::cout << "\n"; + } + } + +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..cf43159 --- /dev/null +++ b/text.h @@ -0,0 +1,12 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED + +#include + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + +void +show_histogram_text(std::vector& bins); + +#endif // TEXT_H_INCLUDED