From 4300a78aad558a4ca037a414788bb7c33531be42 Mon Sep 17 00:00:00 2001 From: "Dmitriy (BerezhkovDA)" Date: Wed, 1 May 2024 21:00:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=D0=BD=D0=BA=205.1=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B8=D1=82=20=D0=B7=D0=B0=D0=B1=D1=8B=D1=82=D1=8B?= =?UTF-8?q?=D1=85=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sem2_lab1.sln | 10 ++++ sem2_lab1/.gitignore | 3 +- sem2_lab1/sem2_lab1.cpp | 90 +---------------------------- sem2_lab1/sem2_lab1.vcxproj | 7 +++ sem2_lab1/sem2_lab1.vcxproj.filters | 17 ++++++ 5 files changed, 38 insertions(+), 89 deletions(-) diff --git a/sem2_lab1.sln b/sem2_lab1.sln index 384d6b0..80bfbfa 100644 --- a/sem2_lab1.sln +++ b/sem2_lab1.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sem2_lab1", "sem2_lab1\sem2_lab1.vcxproj", "{618D0355-4122-45FF-B970-B71C7755CBA7}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unittest", "unittest\unittest.vcxproj", "{5B3F651C-066D-4AF0-8939-4D8E5EB02872}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -21,6 +23,14 @@ Global {618D0355-4122-45FF-B970-B71C7755CBA7}.Release|x64.Build.0 = Release|x64 {618D0355-4122-45FF-B970-B71C7755CBA7}.Release|x86.ActiveCfg = Release|Win32 {618D0355-4122-45FF-B970-B71C7755CBA7}.Release|x86.Build.0 = Release|Win32 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Debug|x64.ActiveCfg = Debug|x64 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Debug|x64.Build.0 = Debug|x64 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Debug|x86.ActiveCfg = Debug|Win32 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Debug|x86.Build.0 = Debug|Win32 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Release|x64.ActiveCfg = Release|x64 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Release|x64.Build.0 = Release|x64 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Release|x86.ActiveCfg = Release|Win32 + {5B3F651C-066D-4AF0-8939-4D8E5EB02872}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sem2_lab1/.gitignore b/sem2_lab1/.gitignore index 85c840e..d7ef128 100644 --- a/sem2_lab1/.gitignore +++ b/sem2_lab1/.gitignore @@ -2,4 +2,5 @@ /.vs /_sem2_lab1_02 /sem2_lab1/x64 -/x64 \ No newline at end of file +/x64 +/unittest/x64 \ No newline at end of file diff --git a/sem2_lab1/sem2_lab1.cpp b/sem2_lab1/sem2_lab1.cpp index 00e875c..005c754 100644 --- a/sem2_lab1/sem2_lab1.cpp +++ b/sem2_lab1/sem2_lab1.cpp @@ -3,8 +3,8 @@ #include #include -#define MAX_STR_LNG 80 -#define PREFIX 4 +#include "histogram.h" +#include "show_histogram.h" using namespace std; struct Input { @@ -25,92 +25,6 @@ Input input_data() } return in; } - -void find_minmax(const vector& 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 make_histogram(const vector& numbers, size_t bin_count) -{ - vector bins; - double min, max; - find_minmax(numbers, min, max); - int number_count = numbers.size(); - bins.resize(bin_count); - double bin_size = (max - min) / bin_count; - for (int i = 0; i < number_count; i++) - { - bool found = false; - for (int 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; -} - -void show_histogram_text(const vector& bins) -{ - //Находим максимум значений корзин - int max_count = bins[0]; - for (int x : bins) - { - if (x > max_count) max_count = x; - } - //Определяем надо ли масштабировать данные - int K; - if (max_count <= (MAX_STR_LNG - PREFIX)) - { - K = 0; - } - else - { - K = 1; - } - - //Строим гистограмму - int cnt; - int bin_sz = bins.size(); - for (int i = 0; i < bin_sz; i++) - { - cout.width(3); - cout.fill(' '); - cout << bins[i] << "|"; - if (K == 0) - cnt = bins[i]; - else - cnt = bins[i] * (MAX_STR_LNG - PREFIX) / max_count; - - for (double j = 0; j < cnt; j++) { - cout << "*"; - } - cout << endl; - } -} - - int main() { auto in = input_data(); diff --git a/sem2_lab1/sem2_lab1.vcxproj b/sem2_lab1/sem2_lab1.vcxproj index a9d3d9a..88cb2e8 100644 --- a/sem2_lab1/sem2_lab1.vcxproj +++ b/sem2_lab1/sem2_lab1.vcxproj @@ -127,11 +127,18 @@ + + + + + + + diff --git a/sem2_lab1/sem2_lab1.vcxproj.filters b/sem2_lab1/sem2_lab1.vcxproj.filters index b60e906..e60da40 100644 --- a/sem2_lab1/sem2_lab1.vcxproj.filters +++ b/sem2_lab1/sem2_lab1.vcxproj.filters @@ -18,8 +18,25 @@ Исходные файлы + + Исходные файлы + + + Исходные файлы + + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + \ No newline at end of file