From 965b055f001e5f205de705ec1edf666185baeffd Mon Sep 17 00:00:00 2001 From: "Arina (SokolAA)" Date: Mon, 2 Jun 2025 12:35:00 +0300 Subject: [PATCH] code: lab4 add curl file --- histogram.cpp | 22 +++++------ histogram.h | 8 ++-- histogram_internal.h | 5 +-- lab01.cbp | 5 +++ main.cpp | 89 +++++++++++++++++++++++++++----------------- svg.cpp | 8 ++-- svg.h | 6 +-- 7 files changed, 83 insertions(+), 60 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index aaeab05..641db08 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,8 +1,8 @@ #include "histogram.h" #include -using std::vector; -// Поиск минимума и максимума -void find_minmax(const std::vector& numbers, double& min, double& max) { +using namespace std; + +void find_minmax(const vector& numbers, double& min, double& max) { if (numbers.empty()) { min = 0; @@ -17,21 +17,18 @@ void find_minmax(const std::vector& numbers, double& min, double& max) { } } -// Расчёт гистограммы -std::vector make_histogram(const std::vector& numbers, size_t bin_count) { - std::vector bins(bin_count, 0); - +vector make_histogram(vector numbers, size_t bin_count) { double min, max; find_minmax(numbers, min, max); - double bin_size = (max - min) / bin_count; + vector bins(bin_count); - for (double number : numbers) { + for (size_t i = 0; i < numbers.size(); i++) { bool found = false; for (size_t j = 0; (j < bin_count - 1) && !found; j++) { - double lo = min + j * bin_size; - double hi = min + (j + 1) * bin_size; - if ((lo <= number) && (number < hi)) { + auto lo = min + j * bin_size; + auto hi = min + (j + 1) * bin_size; + if ((lo <= numbers[i]) && (numbers[i] < hi)) { bins[j]++; found = true; } @@ -40,6 +37,5 @@ std::vector make_histogram(const std::vector& numbers, size_t bi bins[bin_count - 1]++; } } - return bins; } diff --git a/histogram.h b/histogram.h index 5cbcfb1..1ee7f4d 100644 --- a/histogram.h +++ b/histogram.h @@ -1,9 +1,9 @@ #ifndef HISTOGRAM_H_INCLUDED #define HISTOGRAM_H_INCLUDED + #include -using std::vector; -std::vector -make_histogram(const std::vector& numbers, size_t bin_count); +using namespace std; +vector make_histogram(vector numbers, size_t bin_count); -#endif // HISTOGRAM_H_INCLUDED +#endif diff --git a/histogram_internal.h b/histogram_internal.h index 743a766..7b204e9 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -1,7 +1,6 @@ #ifndef HISTOGRAM_INTERNAL_H_INCLUDED #define HISTOGRAM_INTERNAL_H_INCLUDED -#include -using std::vector; + void find_minmax(const std::vector& numbers, double& min, double& max); -#endif // HISTOGRAM_INTERNAL_H_INCLUDED +#endif diff --git a/lab01.cbp b/lab01.cbp index 4a51ce2..779d7ba 100644 --- a/lab01.cbp +++ b/lab01.cbp @@ -13,7 +13,12 @@