MaryK 2 лет назад
Родитель d00907a5f2
Сommit 906ce313db

Двоичные данные
bin/Debug/devlab1.exe

Двоичный файл не отображается.

@ -35,7 +35,12 @@
<Linker>
<Add option="-static-libstdc++" />
</Linker>
<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 />
</Project>
</CodeBlocks_project_file>

@ -1,5 +1,18 @@
# depslib dependency file v1.0
1676897437 source:c:\program files\codeblocks\devlab1\main.cpp
1680528158 source:c:\program files\codeblocks\devlab1\main.cpp
<iostream>
<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>

@ -2,9 +2,29 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3670" topLine="115" />
<Cursor1 position="123" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="69" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="344" topLine="12" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="187" topLine="7" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -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

@ -1,5 +1,8 @@
#include <iostream>
#include <vector>
#include "histogram.h"
#include "text.h"
using namespace std;
struct Input
@ -23,61 +26,7 @@ input_data()
return in;
}
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;
}
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;
}
}
}
int main()
{
auto in = input_data();

Двоичные данные
obj/Debug/histogram.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/main.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/text.o

Двоичный файл не отображается.

@ -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>
Загрузка…
Отмена
Сохранить