Разбиение функций на файлы

master
Oleg 2 лет назад
Родитель d5d7078437
Сommit a07b829f1d

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -0,0 +1,42 @@
#include "histogram.h"
using namespace std;
void
find_minmax(const vector<double>& numbers, double& min, double& max) {
min = numbers[0];
max = numbers[0];
for (double x : numbers) {
if (x < min) {
min = x;
}
else if (x > max) {
max = x;
}
}
}
vector<size_t>
make_histogram(const vector<double>& numbers, size_t bin_count){
double min, max;
find_minmax(numbers, min, max);
double bin_size = (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 * 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]++;
}
}
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,8 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
#include <vector>
void find_minmax(const std::vector<double>& numbers, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -0,0 +1,26 @@
# depslib dependency file v1.0
1692021874 source:c:\users\texas\desktop\1 lab\main.cpp
<iostream>
<vector>
1693205934 source:c:\users\texas\desktop\lab01\main.cpp
"histogram.h"
"text.h"
<iostream>
<vector>
<math.h>
1693204203 c:\users\texas\desktop\lab01\histogram.h
<vector>
1693205331 source:c:\users\texas\desktop\lab01\histogram.cpp
"histogram.h"
1693205776 source:c:\users\texas\desktop\lab01\text.cpp
"histogram.h"
<iostream>
1693209461 c:\users\texas\desktop\lab01\text.h
<vector>
<iostream>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="8" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="12" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="8" zoom_2="0">
<Cursor>
<Cursor1 position="109" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="8" zoom_2="0">
<Cursor>
<Cursor1 position="326" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="13" zoom_2="0">
<Cursor>
<Cursor1 position="122" topLine="0" />
</Cursor>
</File>
<File name=".gitignore" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="7" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -0,0 +1,23 @@
#include "text.h"
#include <vector>
#include <iostream>
using namespace std;
void
show_histogram_text(vector<size_t>& bins, size_t bin_count, float n){
if (n != 0){
cout << "bin count = " << bin_count;
if (n == 1)
cout << " using 1st" << '\n';
else
cout << " using 2nd" << '\n';}
for (size_t i = 0; i < bin_count; i++) {
if (bins[i]<100)
cout << " ";
if (bins[i]<10)
cout << " ";
cout << bins[i] << "|";
for (size_t j = 0; j < bins[i]; j++){
cout << "*";}
cout << '\n';}
}

@ -0,0 +1,8 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
#include <iostream>
void show_histogram_text(std::vector<size_t>& bins, size_t bin_count, float n);
#endif // TEXT_H_INCLUDED

@ -0,0 +1,38 @@
<?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>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,12 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
find_minmax({1, 2}, min, max);
CHECK(min == 1);
CHECK(max == 2);
}
Загрузка…
Отмена
Сохранить