From 9fe03ce72f0b0bc86b02c688444751322195328d Mon Sep 17 00:00:00 2001 From: OvsiannikovRS Date: Sun, 25 May 2025 22:06:39 +0300 Subject: [PATCH] =?UTF-8?q?build:=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B0=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LR3/histogram.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ LR3/histogram.h | 10 ++++++++++ LR3/text.cpp | 14 ++++++++++++++ LR3/text.h | 9 +++++++++ 4 files changed, 75 insertions(+) create mode 100644 LR3/histogram.cpp create mode 100644 LR3/histogram.h create mode 100644 LR3/text.cpp create mode 100644 LR3/text.h diff --git a/LR3/histogram.cpp b/LR3/histogram.cpp new file mode 100644 index 0000000..0930495 --- /dev/null +++ b/LR3/histogram.cpp @@ -0,0 +1,42 @@ +#include "histogram.h" + + +using namespace std; + +void +find_minmax(vector numbers, double& min, double& max) { + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } + } +} + +vector +make_histogram(vector numbers, int bin_count){ + vector bins(bin_count); + double min = numbers[0]; + double max = numbers[0]; + find_minmax(numbers, min, max); + double bin_size = (max - min) / bin_count; + for (auto x: numbers) { + 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 <= x) && (x < hi)) { + bins[j]++; + found = true; + } + } + if (!found) { + bins[bin_count - 1]++; + } + } + return bins; +} diff --git a/LR3/histogram.h b/LR3/histogram.h new file mode 100644 index 0000000..f1dd6c6 --- /dev/null +++ b/LR3/histogram.h @@ -0,0 +1,10 @@ +#ifndef HISTOGRAM_H_INCLUDED +#define HISTOGRAM_H_INCLUDED +#include + +std::vector +make_histogram(std::vector numbers, size_t bin_count); + + + +#endif // HISTOGRAM_H_INCLUDED diff --git a/LR3/text.cpp b/LR3/text.cpp new file mode 100644 index 0000000..9a2b870 --- /dev/null +++ b/LR3/text.cpp @@ -0,0 +1,14 @@ +#include "text.h" + +using namespace std; + +void +show_histogram_text(vector bins){ + for(size_t count: bins){ + if (count < 100) cout << " "; + if (count < 10) cout << " "; + cout << count << "|"; + for(size_t i = 0; i < count; ++i) cout << "*"; + cout << "\n"; + } +} diff --git a/LR3/text.h b/LR3/text.h new file mode 100644 index 0000000..bf84f23 --- /dev/null +++ b/LR3/text.h @@ -0,0 +1,9 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED +#include +#include +using namespace std; +void show_histogram_text(vector bins); + + +#endif // TEXT_H_INCLUDED