diff --git a/.gitignore b/.gitignore index 1a22a74..34339e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ bin/ -cs-lab34.cbp cs-lab34.depend obj/ diff --git a/cs-lab34.cbp b/cs-lab34.cbp new file mode 100644 index 0000000..49b0653 --- /dev/null +++ b/cs-lab34.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/histogram.cpp b/histogram.cpp index d286cb6..ae048fb 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,5 +1,5 @@ #include "histogram.h" -void static find_minmax(vector vec, double& min, double& max) { +void find_minmax(vector vec, double& min, double& max) { min = vec[0]; max = vec[0]; for (double x : vec) { diff --git a/histogram.h b/histogram.h index 1892457..6febae0 100644 --- a/histogram.h +++ b/histogram.h @@ -1,5 +1,4 @@ #include #include using namespace std; -void static find_minmax(vector vec, double& min, double& max); vector make_histogram(size_t number, vector vec); diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..819c07f --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1 @@ +void find_minmax(std::vector vec, double& min, double& max); diff --git a/main.cpp b/main.cpp index ba0f42f..48bcd53 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include "histogram.h" +#include "text.h" struct Input { vector vec; size_t korz{}; @@ -19,83 +20,5 @@ Input input_data() { int main() { auto in = input_data(); auto bins = make_histogram(in.korz, in.vec); - bool gigant = false; - auto spaces = 0; - size_t mx_count = 0; - for (auto x : bins) { - if (x > 76) { - gigant = true; - } - if (x > mx_count) { - mx_count = x; - } - auto len = 0; - while (x > 0) { - x /= 10; - len++; - } - if (len > spaces) { - spaces = len; - } - - } - if (spaces == 1) { - for (size_t i = 0; i < bins.size(); i++) { - std::cout << " " << bins[i] << "|"; - if (gigant) { - if (bins[i] == mx_count) { - for (size_t j = 0; j < 76; j++) { - std::cout << "*"; - } - } - else - { - for (size_t j = 0; j < 76 * static_cast(bins[i]) / mx_count; j++) { - std::cout << "*"; - } - } - } - else - { - for (size_t j = 0; j < bins[i]; j++) { - std::cout << "*"; - } - std::cout << std::endl; - } - } - } - else - { - for (size_t i = 0; i < bins.size(); i++) { - int len = 1; - int k = bins[i]; - for (; k /= 10; ++len); - while (len < spaces) { - std::cout << " "; - len++; - } - std::cout << bins[i]; - std::cout << "|"; - if (gigant) { - if (bins[i] == mx_count) { - for (size_t j = 0; j < 76; j++) { - std::cout << "*"; - } - } - else - { - for (size_t j = 0; j < (76 * static_cast(bins[i]) / mx_count - 1); j++) { - std::cout << "*"; - } - } - } - else - { - for (size_t j = 0; j < bins[i]; j++) { - std::cout << "*"; - } - } - std::cout << std::endl; - } - } + show_histogram(bins); } diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..57e803a --- /dev/null +++ b/text.cpp @@ -0,0 +1,83 @@ +#include "text.h" + +void show_histogram(std::vector bins) { + bool gigant = false; + auto spaces = 0; + size_t mx_count = 0; + for (auto x : bins) { + if (x > 76) { + gigant = true; + } + if (x > mx_count) { + mx_count = x; + } + auto len = 0; + while (x > 0) { + x /= 10; + len++; + } + if (len > spaces) { + spaces = len; + } + + } + if (spaces == 1) { + for (size_t i = 0; i < bins.size(); i++) { + std::cout << " " << bins[i] << "|"; + if (gigant) { + if (bins[i] == mx_count) { + for (size_t j = 0; j < 76; j++) { + std::cout << "*"; + } + } + else + { + for (size_t j = 0; j < 76 * static_cast(bins[i]) / mx_count; j++) { + std::cout << "*"; + } + } + } + else + { + for (size_t j = 0; j < bins[i]; j++) { + std::cout << "*"; + } + std::cout << std::endl; + } + } + } + else + { + for (size_t i = 0; i < bins.size(); i++) { + int len = 1; + int k = bins[i]; + for (; k /= 10; ++len); + while (len < spaces) { + std::cout << " "; + len++; + } + std::cout << bins[i]; + std::cout << "|"; + if (gigant) { + if (bins[i] == mx_count) { + for (size_t j = 0; j < 76; j++) { + std::cout << "*"; + } + } + else + { + for (size_t j = 0; j < (76 * static_cast(bins[i]) / mx_count - 1); j++) { + std::cout << "*"; + } + } + } + else + { + for (size_t j = 0; j < bins[i]; j++) { + std::cout << "*"; + } + } + std::cout << std::endl; + } + } +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..2bf2f23 --- /dev/null +++ b/text.h @@ -0,0 +1,3 @@ +#include +#include +void show_histogram(std::vector bins);