From 703a7496c9456f9d0e8ec44070a4a6ecaab2d193 Mon Sep 17 00:00:00 2001 From: KalenskovaDA Date: Mon, 23 Jun 2025 15:47:21 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- laba1.depend | 2 +- svg.cpp | 19 ++++++++++++++----- unittest.depend | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/laba1.depend b/laba1.depend index c602164..2872c7c 100644 --- a/laba1.depend +++ b/laba1.depend @@ -92,7 +92,7 @@ 1748392232 c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\histogram_internal.h -1749627705 source:c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\main.cpp +1749630788 source:c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\main.cpp diff --git a/svg.cpp b/svg.cpp index 21b455e..ad82036 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,5 +1,6 @@ #include "svg.h" #include +#include using namespace std; void svg_begin(double width, double height) { @@ -10,7 +11,8 @@ void svg_begin(double width, double height) { // Стили для SVG cout << "\n"; } @@ -24,9 +26,10 @@ void svg_text(double left, double baseline, string text) { << text << ""; } -void svg_rect(double x, double y, double width, double height) { - cout << ""; +void svg_rect(double x, double y, double width, double height, bool is_above_average) { + string bar_class = is_above_average ? "bar-red" : "bar-green"; + cout << ""; } void show_histogram_svg(const vector& bins) { @@ -46,10 +49,16 @@ void show_histogram_svg(const vector& bins) { if (count > max_count) max_count = count; } + // Вычисляем среднюю высоту столбца + double average_height = 0; + if (!bins.empty()) { + average_height = accumulate(bins.begin(), bins.end(), 0.0) / bins.size(); + } + for (size_t bin : bins) { const double bin_width = MAX_WIDTH * (static_cast(bin) / max_count); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, bin > average_height); top += BIN_HEIGHT; } diff --git a/unittest.depend b/unittest.depend index bf57c86..ded2e8d 100644 --- a/unittest.depend +++ b/unittest.depend @@ -78,11 +78,11 @@ 1748392232 c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\histogram_internal.h -1748876656 source:c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\svg.cpp +1749628551 source:c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\svg.cpp "svg.h" -1748810901 c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\svg.h +1749627429 c:\users\aleks\onedrive\Рабочий стол\laba1 — копияbb\svg.h