KonovalovaAA 2 лет назад
Родитель 2080964591
Сommit 3f2a04f00d

@ -32,7 +32,12 @@
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Extensions />
</Project>
</CodeBlocks_project_file>

@ -1,29 +1,11 @@
#include <iostream>
#include <vector>
#include <cmath>
#include <windows.h>
#include "histogram.h"
#include "svg.h"
using namespace std;
void
find_minmax(const vector<double> numbers, double& min, double& max)
{
min = numbers[0];
max = numbers[0];
size_t number_count = numbers.size();
for (size_t i = 1; i < number_count; i++)
{
if (numbers[i] < min)
{
min = numbers[i];
}
else if (numbers[i] > max)
{
max = numbers[i];
}
}
}
struct Input
{
vector<double> numbers;
@ -32,31 +14,24 @@ struct Input
Input
input_data()
{
size_t number_count;
cin >> number_count;
cerr << "Enter number_count "; cin >> number_count;
vector<double> numbers(number_count);
for (size_t i = 0; i < number_count; i++)
{
cin >> numbers[i];
}
size_t bin_count;
cin >> bin_count;
Input in;
in.numbers.resize(number_count);
cerr << "Enter numbers ";
for (size_t i = 0; i < number_count; i++)
{
cin >> in.numbers[i];
}
size_t bin_count;
cerr << "Enter bin_count ";
cin >> in.bin_count;
return in;
@ -64,45 +39,13 @@ input_data()
vector<size_t>
make_histogram(vector<double> numbers, size_t bin_count)
{
double min, max;
vector<size_t> bins(bin_count);
double bin_size = (max - min) / bin_count;
find_minmax(numbers, min, max);
size_t number_count = numbers.size();
for (size_t i = 0; i < number_count; 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]) && (numbers[i] < hi))
{
bins[j]++;
found = true;
}
}
if (!found)
{
bins[bin_count - 1]++;
}
}
}
int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
//show_histogram_text(bins, ...);
show_histogram_svg(bins);
return 0;
}

Загрузка…
Отмена
Сохранить