From 24e2e418f28eb3f9fb85ab6a6f8a2ca4d507a013 Mon Sep 17 00:00:00 2001 From: "lab34 (BakaikinKV)" Date: Wed, 16 Apr 2025 17:58:22 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20.h=20=D0=B8=20.cpp=20(text)=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D1=8B=20=D0=B8=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B5=20main.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 38 +------------------------------------- text.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ text.h | 6 ++++++ 3 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 text.cpp create mode 100644 text.h diff --git a/main.cpp b/main.cpp index c30f1fb..86eba5f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include "histogram.h" +#include "text.h" using namespace std; struct Input { @@ -27,44 +28,7 @@ input_data(){ -void show_histogram_text(vector bins, size_t bin_count){ - const size_t SCREEN_WIDTH = 80; - const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; - size_t max_bin = bins[0]; - for(size_t i = 0; i < bin_count; i++) - { - if(bins[i] > max_bin) - { - max_bin = bins[i]; - } - } - - for (size_t bin: bins) - { - size_t height = bin; - - if (max_bin > MAX_ASTERISK) - { - height = MAX_ASTERISK * (static_cast(bin) / max_bin); - } - - if (bin < 100) - { - cout << ' '; - } - if (bin < 10) - { - cout << ' '; - } - cout << bin << "|"; - for(size_t i = 0; i < height; i++) - { - cout << "*"; - } - cout << endl; - } -} int main() { auto in = input_data(); diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..03aa0c5 --- /dev/null +++ b/text.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "text.h" + +using namespace std; + +void show_histogram_text(vector bins, size_t bin_count){ + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + + size_t max_bin = bins[0]; + for(size_t i = 0; i < bin_count; i++) + { + if(bins[i] > max_bin) + { + max_bin = bins[i]; + } + } + + for (size_t bin: bins) + { + size_t height = bin; + + if (max_bin > MAX_ASTERISK) + { + height = MAX_ASTERISK * (static_cast(bin) / max_bin); + } + + if (bin < 100) + { + cout << ' '; + } + if (bin < 10) + { + cout << ' '; + } + cout << 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..d73526b --- /dev/null +++ b/text.h @@ -0,0 +1,6 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED +#include +void show_histogram_text(std::vector bins, size_t bin_count); + +#endif // TEXT_H_INCLUDED