From fb22cec1ec0f87fad2c251340a4456a5b27aa3b5 Mon Sep 17 00:00:00 2001 From: AkinshinaDA Date: Thu, 10 Apr 2025 13:56:28 +0300 Subject: [PATCH] =?UTF-8?q?build:=205.=20=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B3=D0=B8=D1=81=D1=82=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC?= =?UTF-8?q?=D1=8B=20=D0=BA=D0=B0=D0=BA=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B0=D1=82=D0=B5=20SVG.=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=8B=20=D1=81=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D0=BC=20SVG.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 5 ++--- marks.txt | 3 +++ marks_svg.bat | 1 + svg.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ svg.h | 7 +++++++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 marks.txt create mode 100644 marks_svg.bat create mode 100644 svg.cpp create mode 100644 svg.h diff --git a/main.cpp b/main.cpp index 11fa617..c6d217e 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include #include "histogram.h" #include "text.h" +#include "svg.h" using namespace std; struct Input { vector numbers; @@ -24,7 +25,5 @@ input_data(){ int main(){ auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(in.bin_count, bins); - getch(); - return 0; + show_histogram_svg(bins); } diff --git a/marks.txt b/marks.txt new file mode 100644 index 0000000..4ff339c --- /dev/null +++ b/marks.txt @@ -0,0 +1,3 @@ +10 +3 3 4 4 4 4 4 5 5 5 +3 \ No newline at end of file diff --git a/marks_svg.bat b/marks_svg.bat new file mode 100644 index 0000000..75d9155 --- /dev/null +++ b/marks_svg.bat @@ -0,0 +1 @@ +lab1.exe marks.svg \ No newline at end of file diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..f38c2d0 --- /dev/null +++ b/svg.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include "svg.h" +using namespace std; + +void svg_begin(double width, double height) { + cout << "\n"; + cout << "\n"; +} +void svg_end() { + cout << "\n"; +} +void svg_text(double left, double baseline, string text){ + cout << "" << text << "\n"; +} +void svg_rect(double x, double y, double width, double height, string stroke= "black", string fill = "black"){ + cout << ""; +} +void show_histogram_svg(const vector& bins) { + const auto IMAGE_WIDTH = 400; + const auto IMAGE_HEIGHT = 300; + const auto TEXT_LEFT = 20; + const auto TEXT_BASELINE = 20; + const auto TEXT_WIDTH = 50; + const auto BIN_HEIGHT = 30; + const auto BLOCK_WIDTH = 10; + svg_begin(400, 300); + const size_t MAX_DOT = IMAGE_WIDTH - TEXT_WIDTH; + double MAX_BIN = bins[0]; + for (size_t j = 1; j < bins.size(); j++){ + if (bins[j] > MAX_BIN) MAX_BIN = bins[j]; + } + double top = 0; + for (size_t bin : bins) { + double bin_width = BLOCK_WIDTH * bin; + if (bin == MAX_BIN){ + bin_width = MAX_DOT; + } + else bin_width = ceil(MAX_DOT * (bin / MAX_BIN)); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "cyan"); + top += BIN_HEIGHT; + } + svg_end(); +} diff --git a/svg.h b/svg.h new file mode 100644 index 0000000..ff87736 --- /dev/null +++ b/svg.h @@ -0,0 +1,7 @@ +#ifndef SVG_H_INCLUDED +#define SVG_H_INCLUDED +#include + +void show_histogram_svg(const std::vector& bins); + +#endif // SVG_H_INCLUDED