Сравнить коммиты

...

11 Коммитов

@ -32,7 +32,12 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="text.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="339" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="843" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="116" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="93" topLine="0" />
</Cursor>
</File>
<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="205" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="297" topLine="9" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -0,0 +1,42 @@
#include "histogram.h"
#include <vector>
#include <algorithm>
size_t find_minmax(const std::vector<double>& numbers, double& min, double& max) {
if (numbers.empty()) {
min = max = 0;
return 0;
}
min = numbers[0];
max = numbers[0];
for (double number : numbers) {
if (number < min) {
min = number;
}
if (number > max) {
max = number;
}
}
return 0;
}
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count) {
std::vector<size_t> bins(bin_count, 0);
if (numbers.empty() || bin_count == 0) {
return bins;
}
double min, max;
find_minmax(numbers, min, max);
if (max == min) {
return bins; // Âîçâðàùàåì ïóñòûå êîðçèíû, findòàê êàê ãèñòîãðàììà íå ìîæåò áûòü ïîñòðîåíà
}
double bin_width = (max - min) / bin_count;
for (double number : numbers) {
size_t bin_index = static_cast<size_t>((number - min) / bin_width);
if (bin_index >= bin_count) {
bin_index = bin_count - 1; // Îáðàáîòêà êðàéíåãî ñëó÷àÿ max == number
}
bins[bin_index]++;
}
return bins;
};

@ -0,0 +1,4 @@
#pragma once
#include <vector>
size_t find_minmax(const std::vector<double>& numbers, double& min, double& max);
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);

@ -0,0 +1,3 @@
#pragma once
#include <vector>
size_t find_minmax(const std::vector<double>& numbers, double& min, double& max);

@ -1,6 +1,29 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
struct Input{
std::vector<double> numbers;
size_t bin_count{};
};
Input input_data() {
size_t number_count;
std::cerr << "Enter number count: ";
std::cin >> number_count;
std::cerr << "Enter numbers: \n";
Input in;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; ++i) {
std::cin >> in.numbers[i];
}
std::cerr << "Enter bucket: ";
std::cin >> in.bin_count;
return in;
};
using namespace std; using namespace std;

@ -0,0 +1,27 @@
#include "text.h"
#include <iostream>
#include <vector>
void show_histogram_text(const std::vector<size_t>& bins) {
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t max_bin = 0;
for (size_t bin : bins) {
if (bin > max_bin) {
max_bin = bin;
}
for (size_t bin_value : bins) {
if (bin_value < 100) std::cout << " ";
if (bin_value < 10) std::cout << " ";
std::cout << bin_value << " |";
size_t height = bin_value;
if (max_bin > MAX_ASTERISK) {
height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bin_value) / max_bin));
}
for (size_t i = 0; i < height; ++i) {
std::cout << "*";
}
std::cout << "\n";
}
};

@ -0,0 +1,4 @@
#pragma once
#include <vector>
void show_histogram_text(const std::vector<size_t>& bins);

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

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

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

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

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

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

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

@ -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,44 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "Histogram/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);
}
TEST_CASE("empty vector") {
double min = 0;
double max = 0;
find_minmax({}, min, max);
CHECK(min == 0);
CHECK(max == 0);
}
TEST_CASE("single element vector") {
double min = 0;
double max = 0;
find_minmax({5}, min, max);
CHECK(min == 5);
CHECK(max == 5);
}
TEST_CASE("negative numbers") {
double min = 0;
double max = 0;
find_minmax({-3, -1}, min, max);
CHECK(min == -3);
CHECK(max == -1);
}
TEST_CASE("identical elements") {
double min = 0;
double max = 0;
find_minmax({4, 4, 4}, min, max);
CHECK(min == 4);
CHECK(max == 4);
}

@ -0,0 +1,61 @@
# depslib dependency file v1.0
1745791868 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram.cpp
"histogram.h"
<vector>
<algorithm>
1745791871 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram.h
<vector>
1745793818 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\unittest.cpp
"doctest.h"
"Histogram/histogram_internal.h"
1745792535 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
1745792105 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram_internal.h
<vector>

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