From 14a364b76b501ac81f050d7a9f14a3a88e6e99fc Mon Sep 17 00:00:00 2001 From: LedovskojMM Date: Sun, 28 May 2023 14:10:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D0=B4=D0=B8=D0=B2=D0=B8=D0=B4?= =?UTF-8?q?=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab1.depend | 5 +++-- main.cpp | 5 ++++- svg.cpp | 24 ++++++++++++++++++++---- svg.h | 2 +- unittest.depend | 5 +++-- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lab1.depend b/lab1.depend index fdb4d65..ae3ebd8 100644 --- a/lab1.depend +++ b/lab1.depend @@ -3,7 +3,7 @@ -1682338069 source:c:\users\admin\onedrive\Рабочий стол\lab1\main.cpp +1685271547 source:c:\users\admin\onedrive\Рабочий стол\lab1\main.cpp @@ -12,6 +12,7 @@ "text.h" "svg.h" + "histogam_internal.h" 1682273839 c:\users\admin\onedrive\Рабочий стол\lab1\histogam.h @@ -45,5 +46,5 @@ "svg.h" -1682280301 c:\users\admin\onedrive\Рабочий стол\lab1\svg.h +1685271547 c:\users\admin\onedrive\Рабочий стол\lab1\svg.h diff --git a/main.cpp b/main.cpp index d399bf6..94cfea0 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ #include "text.h" #include "svg.h" #include +#include "histogam_internal.h" using namespace std; @@ -35,6 +36,8 @@ int main() { Input in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins); + double min, max; + find_minmax(in.numbers,min,max); + show_histogram_svg(bins,min,max); return 0; } diff --git a/svg.cpp b/svg.cpp index f81e0c2..5d9d2b4 100644 --- a/svg.cpp +++ b/svg.cpp @@ -6,7 +6,17 @@ #include "svg.h" using namespace std; - +size_t k=0; +float +step(size_t& k, size_t bin_count, double min,double max){ + float interval; + double bin_size= (max-min)/bin_count; + if (k < bin_count - 1){ + interval = min + (k + 1) * bin_size; + k+=1; + } + return interval; +} void svg_begin(double width, double height) { cout << "\n"; @@ -31,7 +41,7 @@ void svg_rect(double x, double y, double width, double height, string colour = " } void -show_histogram_svg(const vector& bins) { +show_histogram_svg(const vector& bins, double min,double max) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; const auto TEXT_LEFT = 20; @@ -39,6 +49,7 @@ show_histogram_svg(const vector& bins) { const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; + const auto INTER_WIDTH=30; double top = 0; double max_count = bins[0]; for (size_t i = 0; i < bins.size(); i++) { @@ -48,9 +59,14 @@ show_histogram_svg(const vector& bins) { svg_begin(400, 300); for (size_t bin : bins) { const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count); - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#FF00FF"); + svg_text(TEXT_LEFT+INTER_WIDTH, top + TEXT_BASELINE, to_string(bin)); + svg_rect(TEXT_WIDTH+INTER_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#FF00FF"); top += BIN_HEIGHT; + if (bin!=bins[bins.size()-1]){ + float inter=step(k,bins.size(),min,max); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(inter)); + top += BIN_HEIGHT; + } } svg_end(); } diff --git a/svg.h b/svg.h index ac36df3..75b2256 100644 --- a/svg.h +++ b/svg.h @@ -2,6 +2,6 @@ #define SVG_H_INCLUDED void -show_histogram_svg(const std::vector& bins); +show_histogram_svg(const std::vector& bins,double min, double max); #endif // SVG_H_INCLUDED diff --git a/unittest.depend b/unittest.depend index 5760bab..8c7924e 100644 --- a/unittest.depend +++ b/unittest.depend @@ -1,10 +1,11 @@ # depslib dependency file v1.0 -1682273864 source:c:\users\admin\onedrive\Рабочий стол\lab1\histogam.cpp +1682280773 source:c:\users\admin\onedrive\Рабочий стол\lab1\histogam.cpp "histogam.h" "histogam_internal.h" + 1682273839 c:\users\admin\onedrive\Рабочий стол\lab1\histogam.h @@ -12,7 +13,7 @@ 1682273796 c:\users\admin\onedrive\Рабочий стол\lab1\histogam_internal.h -1682276727 source:c:\users\admin\onedrive\Рабочий стол\lab1\unittest.cpp +1682276830 source:c:\users\admin\onedrive\Рабочий стол\lab1\unittest.cpp "doctest.h" "histogam_internal.h"