From e7cebd0f149ccdfce179d310907b8601573494b1 Mon Sep 17 00:00:00 2001 From: GordiyevskikDA Date: Tue, 5 Mar 2024 19:49:04 +0300 Subject: [PATCH] =?UTF-8?q?WIP:=20=D0=92=D1=8B=D0=BD=D0=BE=D1=81=20=D1=80?= =?UTF-8?q?=D0=B0=D1=81=D1=87=D1=91=D1=82=D0=B0=20=D0=B4=D0=B8=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D0=BC=D1=8B=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LABA1.cpp | 40 ++++++++++------------------------------ histogram.cpp | 31 +++++++++++++++++++++++++++++++ histogram.h | 7 +++++++ 3 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 histogram.cpp create mode 100644 histogram.h diff --git a/LABA1.cpp b/LABA1.cpp index c0de306..b8f0b2e 100644 --- a/LABA1.cpp +++ b/LABA1.cpp @@ -1,5 +1,14 @@ #include #include +#include "histogram.cpp" +/* +Костыль!!!!! +#include "histogram.h" не работает, тем не менее, всё по методичке +работает только с #include "histogram.cpp" +разобраться!!!!!!!! + +Вынести печать в show_histogram_text(), а его в отдельный cpp и h +*/ using namespace std; struct Input { @@ -20,34 +29,6 @@ input_data() { return in; }; -void FindMinMax(const vector& marks, double & min, double & max) { - max = 0; - min = marks[0]; - for (double x : marks) { - if (x > max) { - max = x; - } - if (x < min) { - min = x; - } - } -}; - -vector MakeHistogram(const vector& marks, int NCharts) { - double interval = 0, i = 0, min = 0, max = 0; - vector chart(NCharts); - FindMinMax(marks, min, max); - interval = (max - min) / NCharts; - for (int x : marks) { - i = 0; - while ((x > min + interval * (i + 1))) { - i += 1; - } - chart[i] += 1; - } - return chart; -}; - int main() { const int shift = 4, maxlen = 80; @@ -76,5 +57,4 @@ int main() } cout << "\n"; } -} - +} \ No newline at end of file diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..4653a64 --- /dev/null +++ b/histogram.cpp @@ -0,0 +1,31 @@ +#include "histogram.h" + +using namespace std; + +void FindMinMax(const vector& marks, double& min, double& max) { + max = 0; + min = marks[0]; + for (double x : marks) { + if (x > max) { + max = x; + } + if (x < min) { + min = x; + } + } +}; + +vector MakeHistogram(const vector& marks, int NCharts) { + double interval = 0, i = 0, min = 0, max = 0; + vector chart(NCharts); + FindMinMax(marks, min, max); + interval = (max - min) / NCharts; + for (int x : marks) { + i = 0; + while ((x > min + interval * (i + 1))) { + i += 1; + } + chart[i] += 1; + } + return chart; +}; \ No newline at end of file diff --git a/histogram.h b/histogram.h new file mode 100644 index 0000000..762c793 --- /dev/null +++ b/histogram.h @@ -0,0 +1,7 @@ +#ifndef HISTOGRAM_H_INCLUDED +#define HISTOGRAM_H_INCLUDED +#include + +std::vector MakeHistogram(const std::vector& marks, int NCharts); + +#endif // HISTOGRAM_H_INCLUDED \ No newline at end of file