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