Hihoffff 2 недель назад
Родитель 5de8e3f61a
Сommit a5aeaa0976

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Lab1" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Lab1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="include" />
</Compiler>
<Linker>
<Add option="-static-libstdc++" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin/Release/Lab1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
<Add directory="include" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="histogram.cpp">
<Option target="Debug" />
</Unit>
<Unit filename="histogram.h">
<Option target="Debug" />
</Unit>
<Unit filename="histogram_internal.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" />
<Unit filename="prot.cpp" />
<Unit filename="prot.h" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp">
<Option target="Debug" />
</Unit>
<Unit filename="text.h">
<Option target="Debug" />
</Unit>
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,45 @@
#include "histogram.h"
std::vector<size_t> make_histogram(std::vector<double> numbers, size_t bin_count)
{
double max;
double min;
std::vector<size_t> bins;
bins.resize(bin_count);
find_minmax(numbers, min, max);
double bin_size = (max - min) / 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 * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (hi > numbers[i])) {
bins[j]++;
found = true;
}
}
if (!found) {
bins[bin_count - 1]++;
}
}
return bins;
}
bool find_minmax(std::vector<double> numbers, double& min, double& max) {
if(numbers.size()==0){
return false;
}
min = numbers[0];
max = numbers[0];
for (double number : numbers) {
if (min > number) {
min = number;
}
if (max < number) {
max = number;
}
}
return true;
}

@ -0,0 +1,10 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
bool find_minmax(std::vector<double> numbers, double& min, double& max);
std::vector<size_t> make_histogram(std::vector<double> numbers, size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED
Загрузка…
Отмена
Сохранить