commit 4bf98f3b3cbb3f51bf2a0a7e4bb4b866dfa7a388 Author: MamakinYR Date: Mon Apr 8 14:54:37 2024 +0300 code: Исходный код ЛР1 diff --git a/lab03.vcxproj b/lab03.vcxproj new file mode 100644 index 0000000..c04030b --- /dev/null +++ b/lab03.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {ea8c3c69-2b94-4077-b0e3-fc47a80031a4} + lab03 + 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/lab1.cpp b/lab1.cpp new file mode 100644 index 0000000..0e3b9cc --- /dev/null +++ b/lab1.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +using namespace std; +int main() +{ + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + int i, j; + double num; + size_t number_count, bin_count; + cerr << "Enter number count: " << "\n"; + cin >> number_count; + vector numbers(number_count); + for (i = 0; i < number_count; i++) + { + cin >> num; + numbers[i] = num; + } + cerr << "Enter bin count: " << "\n"; + cin >> bin_count; + vector bins(bin_count); + for (i = 0; i < bin_count; i++) + { + bins[i] = 0; + } + double min_number = numbers[0]; + double max_number = numbers[0]; + for (double x : numbers) + { + if (x < min_number) + { + min_number = x; + } + else if (x > max_number) + { + max_number = x; + } + } + double bin_size = (max_number - min_number) / 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 lo = min_number + j * bin_size; + auto hi = min_number + (j + 1) * bin_size; + if ((lo <= numbers[i]) && (numbers[i] < hi)) + { + bins[j]++; + found = true; + } + } + if (!found) + { + bins[bin_count - 1]++; + } + } + size_t max_bin_capacity = bins[0]; + for (size_t x : bins) + { + if (x > max_bin_capacity) + { + max_bin_capacity = x; + } + } + size_t height = 0; + for (i = 0; i < bin_count; i++) + { + if (bins[i] < 10) + { + cout << " " << bins[i] << "|"; + } + if ((bins[i] < 100) && (bins[i] > 9)) + { + cout << " " << bins[i] << "|"; + } + if (bins[i] >= 100) + { + cout << bins[i] << "|"; + } + height = MAX_ASTERISK * (static_cast(bins[i]) / max_bin_capacity); + for (j = 0; j < height; j++) + { + cout << "*"; + } + cout << "\n"; + } + return 0; +}