From bf2f00ece1d193f103eb52d2c39b0116e1b0e50c Mon Sep 17 00:00:00 2001 From: Danila Date: Sat, 22 Apr 2023 14:57:56 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=82=D1=80=D0=B5=D1=82=D0=B8=D0=B9=20?= =?UTF-8?q?=D1=8D=D1=82=D0=B0=D0=B9=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?,=20=D0=B4=D0=BE=D1=88=D0=B5=D0=BB=20=D0=B4=D0=BE=204=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=83=D0=BD=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 63 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/main.cpp b/main.cpp index 753abb6..0f6ddd2 100644 --- a/main.cpp +++ b/main.cpp @@ -44,53 +44,46 @@ find_minmax(vector numbers, double& min, double& max) return; } - - - - - -int main() +auto make_histogram (vector numbers, size_t bin_count) { - - const size_t screen_width = 80; - const size_t max_asterisk = screen_width - 3 - 1; - int i, j; - - - Input in = input_data(); - - - - vector bins(in.bin_count); - double min; double max; - find_minmax (in.numbers, min, max); - - double bin_size = (max - min) / in.bin_count; + find_minmax (numbers, min, max); + double bin_size = (max - min) / bin_count; + vector bins(bin_count); - for (size_t i = 0; i < in.numbers.size(); i++) + for (size_t i = 0; i < numbers.size(); i++) { bool found = false; - for (size_t j = 0; (j < in.bin_count - 1) && !found; j++) + 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 <= in.numbers[i]) && (in.numbers[i] < hi)) + if ((lo <= numbers[i]) && (numbers[i] < hi)) { - bins[j] ++; + bins[j]++; found = true; } } + if (!found) { - bins[in.bin_count - 1]++; + bins[bin_count - 1]++; } } + return bins; +} + + +void show_histogram_text(auto bins, size_t bin_count) +{ + const size_t screen_width = 80; + const size_t max_asterisk = screen_width - 3 - 1; + size_t i,j; double max_count; max_count = bins[0]; - for (i=0; i< in.bin_count; i++) + for (i=0; i< bin_count; i++) { if (max_count