From 391ad42372e4f86a1ae4ccbf2bcddc504ebb5daa Mon Sep 17 00:00:00 2001 From: NemykinNO Date: Sun, 4 Jun 2023 09:14:50 +0300 Subject: [PATCH] do 5pynkta --- histogram.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ histogram.h | 10 ++++++++ histogram_internal.h | 8 ++++++ lab3.cbp | 46 +++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 histogram.cpp create mode 100644 histogram.h create mode 100644 histogram_internal.h create mode 100644 lab3.cbp diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..e43d6aa --- /dev/null +++ b/histogram.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include "histogram.h" +using namespace std; + +void +find_minmax(vector numbers, double &min, double &max) +{ + min = numbers[0]; + max = numbers[0]; + for (size_t i = 1; i < numbers.size(); i++) + { + if (min > numbers[i]) + min = numbers[i]; + if (max < numbers[i]) + max = numbers[i]; + } +} + +vector make_histogramm(vectornumbers, size_t bin_count) +{ + double min, max; + find_minmax(numbers, min, max); + double binSize = (max - min) / bin_count; + vector bins(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 * binSize; + auto hi = min + (j + 1) * binSize; + if ((numbers[i] >= lo) && (numbers[i] < hi)) + { + bins[j]++; + found = true; + } + } + if (!found) + bins[bin_count - 1]++; + } + int max_count = bins[0]; + for (size_t i = 0; i < bin_count; i++) + { + if (bins[i] > max_count) + max_count = bins[i]; + } + if (max_count > 76) + { + for (size_t i = 0; i < bin_count; i++) + { + int count = bins[i]; + size_t height = 76 * (static_cast(count) / max_count); + bins[i] = height; + } + } + return bins; +} diff --git a/histogram.h b/histogram.h new file mode 100644 index 0000000..a857690 --- /dev/null +++ b/histogram.h @@ -0,0 +1,10 @@ +#ifndef HISTOGRAM_H_INCLUDED +#define HISTOGRAM_H_INCLUDED + +#include + +std::vector +make_histogramm(std::vector numbers, size_t bin_count); + + +#endif // HISTOGRAM_H_INCLUDED diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..52f6582 --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1,8 @@ +#ifndef HISTOGRAM_INTERNAL_H_INCLUDED +#define HISTOGRAM_INTERNAL_H_INCLUDED + +#include + +void find_minmax(std::vector numbers, double &min, double &max); + +#endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/lab3.cbp b/lab3.cbp new file mode 100644 index 0000000..73e8680 --- /dev/null +++ b/lab3.cbp @@ -0,0 +1,46 @@ + + + + + +