From 1e1bbeed4c26d4b5bb03e6414bd0f7b76d494b1e Mon Sep 17 00:00:00 2001 From: artemzelenov Date: Fri, 21 Apr 2023 11:07:14 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B7=D0=B0=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82=D0=B8=D0=BB=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B8?= =?UTF-8?q?=D1=81=D1=85=D0=BE=D0=B4=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/main.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++ project/project.cbp | 38 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 project/main.cpp create mode 100644 project/project.cbp diff --git a/project/main.cpp b/project/main.cpp new file mode 100644 index 0000000..4970112 --- /dev/null +++ b/project/main.cpp @@ -0,0 +1,89 @@ +#include +#include + +using namespace std; +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + +int main() +{ + size_t number_count; + size_t bin_count; + cerr << "Enter number count: "; + cin >> number_count; + vector numbers(number_count); + for(int i;i> numbers[i]; + } + cerr << "Enter bin count: "; + cin >> bin_count; + vector bins(bin_count); + double min = numbers[0]; + double max = numbers[0]; + for (double x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } +} + size_t countt; + size_t max_count = 0; + double bin_size = (max - min) / bin_count; + for (size_t i = 0; i < number_count; 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]++; + } + } + for (size_t i = 0; i < bin_count; i++){ + if(bins[i]>max_count) + max_count = bins[i]; + + } + size_t height; + for (size_t i = 0; i < bin_count; i++) + { + if (bins[i] < 100) + cout << " "; + if (bins[i] < 10) + cout << " "; + cout<MAX_ASTERISK){ + for (size_t j = 0; j <(height = MAX_ASTERISK * (static_cast(bins[i]) / max_count)) ; j++) + { + cout<<"*"; + } + cout< + + + + +