WIP: Вынос расчёта диаграммы в отдельный файл

master
Данил Гордиевских 1 год назад
Родитель 98e7073453
Сommit e7cebd0f14

@ -1,5 +1,14 @@
#include <iostream>
#include <vector>
#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<double>& 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 <double> MakeHistogram(const vector<double>& marks, int NCharts) {
double interval = 0, i = 0, min = 0, max = 0;
vector<double> 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";
}
}
}

@ -0,0 +1,31 @@
#include "histogram.h"
using namespace std;
void FindMinMax(const vector<double>& 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 <double> MakeHistogram(const vector<double>& marks, int NCharts) {
double interval = 0, i = 0, min = 0, max = 0;
vector<double> 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;
};

@ -0,0 +1,7 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
std::vector<double> MakeHistogram(const std::vector<double>& marks, int NCharts);
#endif // HISTOGRAM_H_INCLUDED
Загрузка…
Отмена
Сохранить