From 3b43df26b7e2b575c84ff79388e899a68a759333 Mon Sep 17 00:00:00 2001 From: AnisenkovPD Date: Fri, 26 Apr 2024 19:15:12 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BC=D1=8B=20=D0=BD=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 96 ++------------------------------------------------------ 1 file changed, 2 insertions(+), 94 deletions(-) diff --git a/main.cpp b/main.cpp index 499e006..8c810cf 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,8 @@ #include #include #include +#include "histogram.h" +#include "text.h" using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; @@ -24,106 +26,12 @@ input_data() { return in; } -void -find_minmax(const vector& numbers, double& min, double& max) { - min = numbers[0]; - for (double x : numbers) - { - if (x < min) - { - min = x; - } - else if (x > max) - { - max = x; - } - } -} - -vector make_histogram(const vector numbers, size_t bin_count){ - vector bins(bin_count); - double max, min = 0; - find_minmax(numbers, min, max); - double bin_size = (max - min) / bin_count; - for (size_t i = 0; i < numbers.size(); i++) { - bool found = false; - for (size_t j = 0; (j < bin_count - 1) && !found; j++) { - auto lo = min + j * bin_size; - auto hi = min + (j + 1) * bin_size; - if ((lo <= numbers[i]) && (numbers[i] < hi)) { - bins[j]++; - found = true; - } - } - if (!found) { - bins[bin_count - 1]++; - } - } - return bins; -} -void show_histogram_text (vector bins){ - size_t max_count = bins[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() { auto in = input_data();