Родитель
d00907a5f2
Сommit
906ce313db
Двоичный файл не отображается.
@ -1,5 +1,18 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1676897437 source:c:\program files\codeblocks\devlab1\main.cpp
|
1680528158 source:c:\program files\codeblocks\devlab1\main.cpp
|
||||||
<iostream>
|
<iostream>
|
||||||
<vector>
|
<vector>
|
||||||
|
"histogram.h"
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1680530141 c:\program files\codeblocks\devlab1\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1680530029 source:c:\program files\codeblocks\devlab1\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1680530385 c:\program files\codeblocks\devlab1\text.h
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
#include "histogram.h"
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
void
|
||||||
|
find_minmax(const vector<double>& numbers, double& min, double& max)
|
||||||
|
{
|
||||||
|
min = numbers[0];
|
||||||
|
max = numbers[0];
|
||||||
|
for ( size_t i=0; i < numbers.size(); i++)
|
||||||
|
{
|
||||||
|
if (numbers[i] > max) max=numbers[i];
|
||||||
|
if (numbers[i] < min) min=numbers[i];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<long long unsigned int>
|
||||||
|
make_histogram(const vector<double>& numbers,size_t bin_count)
|
||||||
|
{
|
||||||
|
float lo,hi,dif;
|
||||||
|
double min, max;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
vector <size_t> bins(bin_count) ;
|
||||||
|
dif=(max - min)/bin_count;
|
||||||
|
for(int i=0; i < numbers.size(); i++)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
for (int j=0; (j < bin_count-1)&&!found; j++)
|
||||||
|
{
|
||||||
|
lo= min + j*dif;
|
||||||
|
hi= min + (j+1)*dif;
|
||||||
|
if ((lo <= numbers[i]) && (numbers[i] <hi ))
|
||||||
|
{
|
||||||
|
bins[j]++;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bins;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef HISTOGRAM_H_INCLUDED
|
||||||
|
#define HISTOGRAM_H_INCLUDED
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
std::vector<size_t>
|
||||||
|
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // HISTOGRAM_H_INCLUDED
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|
||||||
|
find_minmax(const std::vector<double>& numbers, double& min, double& max)
|
||||||
|
|
||||||
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
@ -0,0 +1,16 @@
|
|||||||
|
#include "text.h"
|
||||||
|
void show_histogram_text(vector <size_t> &bins)
|
||||||
|
{
|
||||||
|
for (size_t i=0; i<bins.size(); i++)
|
||||||
|
{
|
||||||
|
if (bins[i]!=0)
|
||||||
|
{
|
||||||
|
cout<<bins[i]<<" | " ;
|
||||||
|
for (size_t j=0; j<bins[i]; j++)
|
||||||
|
{
|
||||||
|
cout<<"*";
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
#include "text.h"
|
||||||
|
void show_histogram_text(std::vector <size_t> &bins)
|
||||||
|
{
|
||||||
|
for (size_t i=0; i<bins.size(); i++)
|
||||||
|
{
|
||||||
|
if (bins[i]!=0)
|
||||||
|
{
|
||||||
|
std::cout<<bins[i]<<" | " ;
|
||||||
|
for (size_t j=0; j<bins[i]; j++)
|
||||||
|
{
|
||||||
|
std::cout<<"*";
|
||||||
|
}
|
||||||
|
std::cout<<std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef TEXT_H_INCLUDED
|
||||||
|
#define TEXT_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void show_histogram_text(std::vector <size_t> &bins);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TEXT_H_INCLUDED
|
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="unittest" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/unittest" 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/unittest" 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" />
|
||||||
|
</Compiler>
|
||||||
|
<Extensions />
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_layout_file>
|
||||||
|
<FileVersion major="1" minor="0" />
|
||||||
|
<ActiveTarget name="Debug" />
|
||||||
|
</CodeBlocks_layout_file>
|
Загрузка…
Ссылка в новой задаче