NemykinNO 2 лет назад
Сommit 391ad42372

@ -0,0 +1,60 @@
#include <math.h>
#include <iostream>
#include <conio.h>
#include <vector>
#include "histogram.h"
using namespace std;
void
find_minmax(vector<double> numbers, double &min, double &max)
{
min = numbers[0];
max = numbers[0];
for (size_t i = 1; i < numbers.size(); i++)
{
if (min > numbers[i])
min = numbers[i];
if (max < numbers[i])
max = numbers[i];
}
}
vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count)
{
double min, max;
find_minmax(numbers, min, max);
double binSize = (max - min) / bin_count;
vector<size_t> bins(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 * binSize;
auto hi = min + (j + 1) * binSize;
if ((numbers[i] >= lo) && (numbers[i] < hi))
{
bins[j]++;
found = true;
}
}
if (!found)
bins[bin_count - 1]++;
}
int max_count = bins[0];
for (size_t i = 0; i < bin_count; i++)
{
if (bins[i] > max_count)
max_count = bins[i];
}
if (max_count > 76)
{
for (size_t i = 0; i < bin_count; i++)
{
int count = bins[i];
size_t height = 76 * (static_cast<double>(count) / max_count);
bins[i] = height;
}
}
return bins;
}

@ -0,0 +1,10 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
std::vector<size_t>
make_histogramm(std::vector<double> numbers, size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED

@ -0,0 +1,8 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
#include <vector>
void find_minmax(std::vector<double> numbers, double &min, double &max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="lab3" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/lab3" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/lab3" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="ddd.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
Загрузка…
Отмена
Сохранить