From a94ec184bf26e115c77733620bf740a3132b422d Mon Sep 17 00:00:00 2001 From: VinogradovMA Date: Fri, 25 Apr 2025 11:46:30 +0300 Subject: [PATCH] code:basement --- .gitignore | 2 + Lab1.cbp | 40 +++++++++++++++++++ main.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 .gitignore create mode 100644 Lab1.cbp create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a079b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin +/obj \ No newline at end of file diff --git a/Lab1.cbp b/Lab1.cbp new file mode 100644 index 0000000..c725d43 --- /dev/null +++ b/Lab1.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ddaa5aa --- /dev/null +++ b/main.cpp @@ -0,0 +1,110 @@ + +#include +#include +#include + +using namespace std; + +void mmV(vector numbers, double& min, double& max); +size_t maxBin(vector bins); + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + + +int main() +{ + vector numbers; + vector bins; + size_t countOfNumbers; + size_t binCount; + size_t maxCount; + double max; + double min; + cerr << "Input your count of numbers:\n"; + cin >> countOfNumbers; + numbers.resize(countOfNumbers); + cerr << "Input numbers:\n"; + for (int i = 0; i < countOfNumbers; i++) { + cerr << i << endl; + cin >> numbers[i]; + } + cerr << endl; + cerr << "Input bin count:\n"; + cin >> binCount; + bins.resize(binCount); + mmV(numbers, min, max); + double bin_size = (max - min) / binCount; + + + for (size_t i = 0; i < countOfNumbers; i++) { + bool found = false; + for (size_t j = 0; (j < binCount - 1) && !found; j++) { + auto lo = min + j * bin_size; + auto hi = min + (j + 1) * bin_size; + if ((lo <= numbers[i]) && (hi > numbers[i])) { + bins[j]++; + found = true; + } + } + if (!found) { + bins[binCount - 1]++; + } + } + maxCount = maxBin(bins); + size_t count_stars; + for (int i = 0; i < binCount; i++) { + + if (bins[i] < 100) { + cout << " "; + } + if (bins[i] < 10) { + cout << " "; + } + + cout << bins[i]; + cout << "|"; + + if (maxCount > MAX_ASTERISK) { + count_stars = MAX_ASTERISK * (static_cast(bins[i]) / maxCount); + } + else { + count_stars = bins[i]; + } + for (size_t i2 = 0; i2 < count_stars; i2++) { + cout << "*"; + } + cout << endl; + + + } + + return 0; +} + +size_t maxBin(vector bins) { //лучше без функции + size_t max = bins[0]; + for (int i = 1; i < bins.size(); i++) { + if (max < bins[i]) { + max = bins[i]; + } + } + return max; +} +void mmV(vector numbers, double& min, double& max) { //сказал сделать без функции + min = numbers[0]; + max = numbers[0]; + for (double number : numbers) { + if (min > number) { + min = number; + } + if (max < number) { + max = number; + } + } + return; +} +//var15 без масштабирования защита + + +