From 6782c9fd6c71963bc27598e6473abb83c7a1d967 Mon Sep 17 00:00:00 2001 From: Tanya Date: Mon, 13 May 2024 15:23:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=B8=D0=B7=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B8=D0=B7=D0=B2=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++++ histogram.cpp | 6 +++++- histogram.h | 4 ++++ histogram_internal.h | 2 +- main.cpp | 13 +------------ svg.cpp | 8 ++++---- 6 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 .gitignore 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