diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c7473d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin +/obj diff --git a/7112 b/7112 new file mode 100644 index 0000000..fce8b58 --- /dev/null +++ b/7112 @@ -0,0 +1,8 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAqjR8VKL +iXqwsebTTkYzLtAAAAGAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIAMVcWMSwkHQ796Q +v12uM1/L9QSqCC1guyCtw8nZgqYaAAAAoAX6y1g+sl014TmIQ7zX/gv2ngRTEKBcujJq8O +UqkMywAQC10aGheZuBego39vP3S84Tf+kKNzxIUWu+kRpbgi4x2bIc5/kYbYh76DGK+o9z +zCGU6ju3j1fNVHknGYkR0aw2SSu9/Q8GjU+xMd5Rdqj567rbHY/w7Qt8ZYImEKVvYoO/6G +BenNIJk2c3S/lY26lh51GG9DF9PKMrnWNhZIY= +-----END OPENSSH PRIVATE KEY----- diff --git a/7112.pub b/7112.pub new file mode 100644 index 0000000..2db8a5b --- /dev/null +++ b/7112.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAMVcWMSwkHQ796Qv12uM1/L9QSqCC1guyCtw8nZgqYa aleks@DESKTOP-3A8L66V diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..25caf89 --- /dev/null +++ b/histogram.cpp @@ -0,0 +1,42 @@ +#include "histogram.h" +#include "histogram_internal.h" +#include +using std::vector; +void find_minmax(const std::vector& numbers, double& min, double& max) { + min = numbers[0]; + max = numbers[0]; + + for (double number : numbers) { + if (number < min) { + min = number; + } + if (number > max) { + max = number; + } + } +} +std::vector make_histogram(const std::vector& numbers, size_t bin_count) { + std::vector bins(bin_count, 0); + + double min, max; + find_minmax(numbers, min, max); + + double bin_size = (max - min) / bin_count; + + for (double number : numbers) { + bool found = false; + for (size_t j = 0; (j < bin_count - 1) && !found; j++) { + double lo = min + j * bin_size; + double hi = min + (j + 1) * bin_size; + if ((lo <= number) && (number < hi)) { + bins[j]++; + found = true; + } + } + if (!found) { + bins[bin_count - 1]++; + } + } + + return bins; +} diff --git a/histogram.h b/histogram.h new file mode 100644 index 0000000..8e11782 --- /dev/null +++ b/histogram.h @@ -0,0 +1,10 @@ +#ifndef HISTOGRAM_H_INCLUDED +#define HISTOGRAM_H_INCLUDED + +#include +using std::vector; +std::vector +make_histogram(const std::vector& numbers, size_t bin_count); + + +#endif // HISTOGRAM_H_INCLUDED diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..de127c5 --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1,8 @@ +#ifndef HISTOGRAM_INTERNAL_H_INCLUDED +#define HISTOGRAM_INTERNAL_H_INCLUDED +#include +using std::vector; +void find_minmax(const std::vector& numbers, double& min, double& max); + + +#endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/laba1.cbp b/laba1.cbp index 10437ba..64477a3 100644 --- a/laba1.cbp +++ b/laba1.cbp @@ -32,6 +32,11 @@ + + + + diff --git a/laba1.depend b/laba1.depend new file mode 100644 index 0000000..c01c32e --- /dev/null +++ b/laba1.depend @@ -0,0 +1,80 @@ +# depslib dependency file v1.0 +1748812442 source:c:\users\aleks\onedrive\Рабочий стол\laba1\main.cpp + + + "histogram.h" + "text.h" + "svg.h" + +1748386910 c:\users\aleks\onedrive\Рабочий стол\laba1\histogram.h + + +1748730472 c:\users\aleks\onedrive\Рабочий стол\laba1\text.h + + +1748808306 source:c:\users\aleks\onedrive\Рабочий стол\laba1\text.cpp + "text.h" + + + +1748392747 c:\users\aleks\onedrive\Рабочий стол\laba1\doctest.h + + + + + + + "doctest_fwd.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1748392232 c:\users\aleks\onedrive\Рабочий стол\laba1\histogram_internal.h + + +1748811805 source:c:\users\aleks\onedrive\Рабочий стол\laba1\svg.cpp + "svg.h" + + +1748810901 c:\users\aleks\onedrive\Рабочий стол\laba1\svg.h + + + +1748808114 source:c:\users\aleks\onedrive\Рабочий стол\laba1\histogram.cpp + "histogram.h" + "histogram_internal.h" + + diff --git a/laba1.exe b/laba1.exe new file mode 100644 index 0000000..e69de29 diff --git a/laba1.layout b/laba1.layout new file mode 100644 index 0000000..617a8b8 --- /dev/null +++ b/laba1.layout @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/laba1/bin/Debug/laba1.exe b/laba1/bin/Debug/laba1.exe new file mode 100644 index 0000000..e69de29 diff --git a/laba1/bin/Debug/marks.svg b/laba1/bin/Debug/marks.svg new file mode 100644 index 0000000..e69de29 diff --git a/laba1/laba1.cbp b/laba1/laba1.cbp new file mode 100644 index 0000000..e5bcdf7 --- /dev/null +++ b/laba1/laba1.cbp @@ -0,0 +1,38 @@ + + + + + + diff --git a/laba1/laba1.depend b/laba1/laba1.depend new file mode 100644 index 0000000..a1b3543 --- /dev/null +++ b/laba1/laba1.depend @@ -0,0 +1,25 @@ +# depslib dependency file v1.0 +1748387373 source:c:\users\aleks\onedrive\Рабочий стол\laba1\histogram.cpp + "histogram.h" + + +1748386910 c:\users\aleks\onedrive\Рабочий стол\laba1\histogram.h + + +1748388937 source:c:\users\aleks\onedrive\Рабочий стол\laba1\main.cpp + + + "histogram.h" + "text.h" + +1748388603 c:\users\aleks\onedrive\Рабочий стол\laba1\text.h + + +1584205420 source:c:\users\aleks\onedrive\Рабочий стол\laba1\laba1\main.cpp + + +1748391445 source:c:\users\aleks\onedrive\Рабочий стол\laba1\text.cpp + "text.h" + + + diff --git a/laba1/laba1.layout b/laba1/laba1.layout new file mode 100644 index 0000000..593c06e --- /dev/null +++ b/laba1/laba1.layout @@ -0,0 +1,5 @@ + + + + + diff --git a/laba1/obj/Debug/histogram.o b/laba1/obj/Debug/histogram.o new file mode 100644 index 0000000..fbb05de Binary files /dev/null and b/laba1/obj/Debug/histogram.o differ diff --git a/laba1/obj/Debug/main.o b/laba1/obj/Debug/main.o new file mode 100644 index 0000000..d443543 Binary files /dev/null and b/laba1/obj/Debug/main.o differ diff --git a/laba1/obj/Debug/text.o b/laba1/obj/Debug/text.o new file mode 100644 index 0000000..57c4d70 Binary files /dev/null and b/laba1/obj/Debug/text.o differ diff --git a/main.cpp b/main.cpp index 8f1c932..1eabfad 100644 --- a/main.cpp +++ b/main.cpp @@ -1,23 +1,24 @@ #include #include - +#include "histogram.h" +#include "text.h" +#include "svg.h" using namespace std; -const size_t SCREEN_WIDTH = 80; -const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + struct Input { - vector numbers; - size_t bin_count{}; + std::vector numbers; + size_t bin_count; }; // Ввод данных Input input_data() { + Input in; size_t number_count; cerr << "Enter number count: "; cin >> number_count; - Input in; in.numbers.resize(number_count); cerr << "Enter numbers: "; @@ -32,83 +33,18 @@ Input input_data() { } // Поиск минимума и максимума -void find_minmax(const vector& numbers, double& min, double& max) { - min = numbers[0]; - max = numbers[0]; - for (double number : numbers) { - if (number < min) { - min = number; - } - if (number > max) { - max = number; - } - } -} // Расчёт гистограммы -vector make_histogram(const vector& numbers, size_t bin_count) { - vector bins(bin_count, 0); - - double min, max; - find_minmax(numbers, min, max); - double bin_size = (max - min) / bin_count; - - for (double number : numbers) { - bool found = false; - for (size_t j = 0; (j < bin_count - 1) && !found; j++) { - double lo = min + j * bin_size; - double hi = min + (j + 1) * bin_size; - if ((lo <= number) && (number < hi)) { - bins[j]++; - found = true; - } - } - if (!found) { - bins[bin_count - 1]++; - } - } - - return bins; -} // Вывод гистограммы -void show_histogram_text(const vector& bins) { - size_t max_bin_count = 0; - for (size_t bin : bins) { - if (bin > max_bin_count) { - max_bin_count = bin; - } - } - if (max_bin_count <= MAX_ASTERISK) { - for (size_t bin : bins) { - if (bin < 10) cout << " "; - cout << " " << bin << "|"; - for (size_t j = 0; j < bin; j++) { - cout << "*"; - } - cout << endl; - } - } else { - for (size_t bin : bins) { - size_t height = static_cast(MAX_ASTERISK * (static_cast(bin) / max_bin_count)); - if (bin < 100) cout << " "; - if (bin < 10) cout << " "; - cout << bin << "|"; - for (size_t j = 0; j < height; j++) { - cout << "*"; - } - cout << endl; - } - } -} // Основная функция int main() { - Input in = input_data(); - vector bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins); + auto in = input_data(); + auto bins = make_histogram(in.numbers, in.bin_count); + show_histogram_svg(bins); return 0; } diff --git a/main.o b/main.o new file mode 100644 index 0000000..650e38a Binary files /dev/null and b/main.o differ diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..a3c3f71 --- /dev/null +++ b/svg.cpp @@ -0,0 +1,68 @@ +#include "svg.h" +#include +using namespace std; +void +svg_begin(double width, double height) { + cout << "\n"; + cout << "\n"; +} + +void +svg_end() { + cout << "\n"; +} +void +svg_text(double left, double baseline, string text) +{ + cout << "" << text << ""; +} + +void +svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black") +{ + cout << ""; + +} + + + +void +show_histogram_svg(const vector& bins) +{ + const auto IMAGE_WIDTH = 400; + const auto IMAGE_HEIGHT = 300; + const auto TEXT_LEFT = 20; + const auto TEXT_BASELINE = 20; + const auto TEXT_WIDTH = 50; + const auto BIN_HEIGHT = 30; + const auto YELLOW = "yellow"; + const auto PURPLE = "purple"; + const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH; + + + svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); + + double top = 0; + double max_count = bins[0]; + for (size_t i = 0; i < bins.size(); i++) + { + if (max_count +#include + +void show_histogram_svg(const std::vector& bins); + +#endif diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..9965a5a --- /dev/null +++ b/text.cpp @@ -0,0 +1,37 @@ +#include "text.h" +#include +#include +using std::vector; +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; +// Âûâîä ãèñòîãðàììû +void show_histogram_text(const std::vector& bins) { + size_t max_bin_count = 0; + for (size_t bin : bins) { + if (bin > max_bin_count) { + max_bin_count = bin; + } + } + + if (max_bin_count <= MAX_ASTERISK) { + for (size_t bin : bins) { + if (bin < 10) std::cout << " "; + std::cout << " " << bin << "|"; + for (size_t j = 0; j < bin; j++) { + std::cout << "*"; + } + std::cout << std::endl; + } + } else { + for (size_t bin : bins) { + size_t height = static_cast(MAX_ASTERISK * (static_cast(bin) / max_bin_count)); + if (bin < 100) std::cout << " "; + if (bin < 10) std::cout << " "; + std::cout << bin << "|"; + for (size_t j = 0; j < height; j++) { + std::cout << "*"; + } + std::cout << std::endl; + } + } +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..7256762 --- /dev/null +++ b/text.h @@ -0,0 +1,9 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED +#include +using std::vector; + +void show_histogram_text(const std::vector& bins); + + +#endif // TEXT_H_INCLUDED diff --git a/unittest.cbp b/unittest.cbp new file mode 100644 index 0000000..7f9621b --- /dev/null +++ b/unittest.cbp @@ -0,0 +1,38 @@ + + + + + + diff --git a/unittest.cpp b/unittest.cpp new file mode 100644 index 0000000..37e5da4 --- /dev/null +++ b/unittest.cpp @@ -0,0 +1,56 @@ +#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); +} +TEST_CASE("distinct negative numbers"){ + double min = 0; + double max = 0; + find_minmax({-1, -2}, min, max); + CHECK(min == -2); + CHECK(max == -1); +} +TEST_CASE("vector of the same elements"){ + double min = 0; + double max = 0; + find_minmax({3,3,3}, min, max); + CHECK(min == 3); + CHECK(max == 3); +} +TEST_CASE("vector of one elements"){ + double min = 0; + double max = 0; + find_minmax({3}, min, max); + CHECK(min == max); +} +TEST_CASE("mixed positive and negative numbers") { + double min = 0; + double max = 0; + find_minmax({-1, 2, 0, -3, 5}, min, max); + CHECK(min == -3); + CHECK(max == 5); +} + +TEST_CASE("vector with all negative numbers") { + double min = 0; + double max = 0; + find_minmax({-5, -10, -2}, min, max); + CHECK(min == -10); + CHECK(max == -2); +} + +TEST_CASE("vector with zero") { + double min = 0; + double max = 0; + find_minmax({0, -1, 1}, min, max); + CHECK(min == -1); + CHECK(max == 1); +} + diff --git a/unittest.depend b/unittest.depend new file mode 100644 index 0000000..f345164 --- /dev/null +++ b/unittest.depend @@ -0,0 +1,68 @@ +# depslib dependency file v1.0 +1748392121 source:c:\users\aleks\onedrive\Рабочий стол\laba1\histogram.cpp + "histogram.h" + + +1748386910 c:\users\aleks\onedrive\Рабочий стол\laba1\histogram.h + + +1748729850 source:c:\users\aleks\onedrive\Рабочий стол\laba1\unittest.cpp + "doctest.h" + "histogram_internal.h" + +1748392747 c:\users\aleks\onedrive\Рабочий стол\laba1\doctest.h + + + + + + + "doctest_fwd.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1748392232 c:\users\aleks\onedrive\Рабочий стол\laba1\histogram_internal.h + + +1748802937 source:c:\users\aleks\onedrive\Рабочий стол\laba1\svg.cpp + "svg.h" + + +1748730522 c:\users\aleks\onedrive\Рабочий стол\laba1\svg.h + + + diff --git a/unittest.layout b/unittest.layout new file mode 100644 index 0000000..593c06e --- /dev/null +++ b/unittest.layout @@ -0,0 +1,5 @@ + + + + +