diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9fa1ef9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +lab34.vcxproj +lab34.vcxproj.filters +lab34.vcxproj.user +/x64 +.vs/ \ No newline at end of file diff --git a/histogram.cpp b/histogram.cpp index cbcd156..4720614 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -3,8 +3,11 @@ #include "histogram_internal.h" using namespace std; -void +bool find_minmax(const vector& numbers, double& min, double& max) { + if (numbers.size() == 0) { + return false; + } min = numbers[0]; max = numbers[0]; for (auto x : numbers) { @@ -13,6 +16,7 @@ find_minmax(const vector& numbers, double& min, double& max) { if (x < min) min = x; } + return true; } vector diff --git a/histogram.h b/histogram.h index a86c9a3..d9585f9 100644 --- a/histogram.h +++ b/histogram.h @@ -3,3 +3,7 @@ std::vector make_histogram(const std::vector& numbers, size_t bin_count); +bool +find_minmax(const std::vector& numbers, double& min, double& max); + + diff --git a/histogram_internal.h b/histogram_internal.h index 357be1f..ff6e9ca 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -1,6 +1,6 @@ #pragma once #include -void +bool find_minmax(const std::vector& numbers, double& min, double& max); diff --git a/main.cpp b/main.cpp index 43cb6df..29a0767 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,7 @@ #include "text.h" #include "svg.h" + using namespace std; @@ -32,18 +33,6 @@ input_data() { return in; } -void -find_minmax(const vector& numbers, double& min, double& max); - -vector -make_histogram(const vector& numbers, size_t bin_count); - -void -show_histogram_text(vector bins); - -void -show_histogram_svg(const vector& bins); - int main() { Input in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); diff --git a/svg.cpp b/svg.cpp index 22a61ce..86fa3ce 100644 --- a/svg.cpp +++ b/svg.cpp @@ -52,10 +52,10 @@ show_histogram_svg(const vector& bins) { if (k > 1) k = 1; for (size_t bin : bins) { - const double bin_width = BLOCK_WIDTH * bin * k; - svg_text(TEXT_LEFT + top, TEXT_BASELINE, to_string(bin)); - svg_rect(top + 13, 3 * BLOCK_WIDTH, BIN_HEIGHT, bin_width, "black", "#87CEEB"); + const double bin_width = BLOCK_WIDTH * bin; + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#87CEEB"); top += BIN_HEIGHT; } svg_end(); -} +} \ No newline at end of file