From c8989f1ba29cf19adbec8e5ff85c1aac685c6057 Mon Sep 17 00:00:00 2001 From: GladkyMS Date: Sun, 21 Apr 2024 14:53:54 +0300 Subject: [PATCH] 1:source code --- .gitignore | 2 + vector.cpp | 81 +++++++++++++++++++++++++ vector.vcxproj | 135 +++++++++++++++++++++++++++++++++++++++++ vector.vcxproj.filters | 22 +++++++ 4 files changed, 240 insertions(+) create mode 100644 .gitignore create mode 100644 vector.cpp create mode 100644 vector.vcxproj create mode 100644 vector.vcxproj.filters diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c06619 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/x64 +vector.vcxproj.user \ No newline at end of file diff --git a/vector.cpp b/vector.cpp new file mode 100644 index 0000000..7ab98d4 --- /dev/null +++ b/vector.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; +using namespace std; +int main() +{ + size_t number_count; + cerr << "Enter number count: "; + cin >> number_count; + vector numbers(number_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; + } + size_t bin_count=3; + vector bins(bin_count); + double bin_size = (max - min) / bin_count; + for (size_t i = 0; i < number_count; i++) + { + bool found = false; + for (size_t j = 0; (j < bin_count - 1) && !found; j++) + { + auto low = min + j * bin_size; + auto high = min + (j + 1) * bin_size; + if ((low <= numbers[i]) && (numbers[i] < high)) + { + bins[j]++; + found = true; + } + } + if (!found) + { + bins[bin_count - 1]++; + } + } + + double mxbins = bins[0]; + + for (double x : bins) + { + if (x > mxbins) + mxbins = x; + } + double k; + + if (mxbins > MAX_ASTERISK) + k = MAX_ASTERISK / mxbins; + else + k = 1; + for (size_t i = 0; i < bin_count; i++) + { + if (bins[i] < 10) { + cout << " "; + } + else if (bins[i] < 100) { + cout << " "; + } + cout << bins[i] << "|"; + + + for (int j = 0; j < floor(bins[i] * k); j++) + { + cout << "*"; + } + + cout << endl; + } +} diff --git a/vector.vcxproj b/vector.vcxproj new file mode 100644 index 0000000..d1aab45 --- /dev/null +++ b/vector.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {9d5f50ad-c81e-4060-83e3-75280ead3b6e} + vector + 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/vector.vcxproj.filters b/vector.vcxproj.filters new file mode 100644 index 0000000..ec22179 --- /dev/null +++ b/vector.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