From b426f22216da979fa3b3c845b9e8b98eab1e883c Mon Sep 17 00:00:00 2001 From: "Dmitriy (BerezhkovDA)" Date: Sun, 21 Apr 2024 14:44:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=D0=BD=D0=BA=D1=82=201.=D0=B8=D0=BC?= =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=82=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=BB?= =?UTF-8?q?=D1=801?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sem2_lab1.sln | 31 +++++++ sem2_lab1/sem2_lab1.cpp | 106 ++++++++++++++++++++++ sem2_lab1/sem2_lab1.vcxproj | 135 ++++++++++++++++++++++++++++ sem2_lab1/sem2_lab1.vcxproj.filters | 22 +++++ sem2_lab1/sem2_lab1.vcxproj.user | 4 + 5 files changed, 298 insertions(+) create mode 100644 sem2_lab1.sln create mode 100644 sem2_lab1/sem2_lab1.cpp create mode 100644 sem2_lab1/sem2_lab1.vcxproj create mode 100644 sem2_lab1/sem2_lab1.vcxproj.filters create mode 100644 sem2_lab1/sem2_lab1.vcxproj.user diff --git a/sem2_lab1.sln b/sem2_lab1.sln new file mode 100644 index 0000000..384d6b0 --- /dev/null +++ b/sem2_lab1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +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 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {618D0355-4122-45FF-B970-B71C7755CBA7}.Debug|x64.ActiveCfg = Debug|x64 + {618D0355-4122-45FF-B970-B71C7755CBA7}.Debug|x64.Build.0 = Debug|x64 + {618D0355-4122-45FF-B970-B71C7755CBA7}.Debug|x86.ActiveCfg = Debug|Win32 + {618D0355-4122-45FF-B970-B71C7755CBA7}.Debug|x86.Build.0 = Debug|Win32 + {618D0355-4122-45FF-B970-B71C7755CBA7}.Release|x64.ActiveCfg = Release|x64 + {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 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {11EBBF31-D83F-4FCC-9216-C9796F60D2E6} + EndGlobalSection +EndGlobal diff --git a/sem2_lab1/sem2_lab1.cpp b/sem2_lab1/sem2_lab1.cpp new file mode 100644 index 0000000..0425f17 --- /dev/null +++ b/sem2_lab1/sem2_lab1.cpp @@ -0,0 +1,106 @@ +// sem2_lab1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы. +// + +#include +#include +#define MAX_STR_LNG 80 +#define PREFIX 4 +using namespace std; + +int main() +{ + int number_count; + int bin_count; + //Ввод данных + cerr << "Enter number count: "; + cin >> number_count; + cerr << "Enter bin count: "; + cin >> bin_count; + vector numbers(number_count); + vector bins(bin_count); + for (int i = 0; i < number_count; i++) + { + cin >> numbers[i]; + } + //Находим минимальное и максимальное значение + double min = numbers[0]; + double max = numbers[0]; + for (double x : numbers) + { + if (x < min) + { + min = x; + } + else if (x > max) + { + max = x; + } + } + //Вычисляем гистограмму + 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]++; + } + } + //Находим максимум значений корзин + 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; + } + //K = 0; // принудительное отключение масштабирования для 1 и 2 + //Строим гистограмму + int cnt; + for (int i = 0; i < bin_count; 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; + } +} + + +// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки" +// Отладка программы: F5 или меню "Отладка" > "Запустить отладку" + +// Советы по началу работы +// 1. В окне обозревателя решений можно добавлять файлы и управлять ими. +// 2. В окне Team Explorer можно подключиться к системе управления версиями. +// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения. +// 4. В окне "Список ошибок" можно просматривать ошибки. +// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода. +// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл. diff --git a/sem2_lab1/sem2_lab1.vcxproj b/sem2_lab1/sem2_lab1.vcxproj new file mode 100644 index 0000000..4c7be1c --- /dev/null +++ b/sem2_lab1/sem2_lab1.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {618d0355-4122-45ff-b970-b71c7755cba7} + sem2lab1 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/sem2_lab1/sem2_lab1.vcxproj.filters b/sem2_lab1/sem2_lab1.vcxproj.filters new file mode 100644 index 0000000..b1c8a99 --- /dev/null +++ b/sem2_lab1/sem2_lab1.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/sem2_lab1/sem2_lab1.vcxproj.user b/sem2_lab1/sem2_lab1.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/sem2_lab1/sem2_lab1.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file