From 4a7ee50d89f87c36c135c10a1e8894b305479cb0 Mon Sep 17 00:00:00 2001 From: GordiyevskikDA Date: Sat, 16 Mar 2024 16:57:32 +0300 Subject: [PATCH] =?UTF-8?q?variant:=20=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B8=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=20=D0=BF=D0=BE=20=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B0=D0=BD=D1=82=D1=83=20=E2=84=967?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LABA1.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/LABA1.cpp b/LABA1.cpp index 88b7ac6..76a75a1 100644 --- a/LABA1.cpp +++ b/LABA1.cpp @@ -35,16 +35,25 @@ void show_histogram_svg(const vector& marks, const vector& chart const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; - double min = 0, max = 0, scale = 1; + double min = 0, max = 0, scale = 1, average = 0, sum = 0; int maxlen = IMAGE_WIDTH - TEXT_WIDTH; svg_begin(4000, 300); double top = 0; + for (double x : chart) { + sum += x; + } + average = sum / chart.size(); FindMinMax(chart, min, max); scale = max * BLOCK_WIDTH / maxlen; for (double bin : chart) { double bin_width = BLOCK_WIDTH * bin; svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string((int)bin)); - svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT); + if (bin > average) { + svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "red"); + } + else { + svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "green"); + } top += BIN_HEIGHT; } svg_end();