From 626f53e9ead54feea17c70aaace8fcbe3357762c Mon Sep 17 00:00:00 2001 From: AndrosovDS Date: Mon, 28 Apr 2025 10:24:23 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20svg.h=20svg.cpp=20=D0=B8=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=20main.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cs-lab34.depend | 29 ++++++++++ main.cpp | 26 +++++---- svg.cpp | 58 +++++++++++++++++++ svg.h | 11 ++++ ...й документ — копия (4).txt | 0 ...й документ — копия (5).txt | 0 6 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 cs-lab34.depend create mode 100644 svg.cpp create mode 100644 svg.h delete mode 100644 Текстовый документ — копия (4).txt delete mode 100644 Текстовый документ — копия (5).txt diff --git a/cs-lab34.depend b/cs-lab34.depend new file mode 100644 index 0000000..76ff32c --- /dev/null +++ b/cs-lab34.depend @@ -0,0 +1,29 @@ +# depslib dependency file v1.0 +1745823834 source:c:\users\diman3000\desktop\cs-lab34\histogram.cpp + "histogram.h" + + +1745823794 c:\users\diman3000\desktop\cs-lab34\histogram.h + + +1745823869 source:c:\users\diman3000\desktop\cs-lab34\text.cpp + "text.h" + + +1745823848 c:\users\diman3000\desktop\cs-lab34\text.h + + +1745824478 source:c:\users\diman3000\desktop\cs-lab34\main.cpp + + + "histogram.h" + "svg.h" + +1745824381 c:\users\diman3000\desktop\cs-lab34\svg.h + + + +1745824404 source:c:\users\diman3000\desktop\cs-lab34\svg.cpp + "svg.h" + + diff --git a/main.cpp b/main.cpp index 6f4e61b..e919aa0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,29 +1,30 @@ #include +#include #include "histogram.h" -#include "text.h" +#include "svg.h" using namespace std; +// struct Input { vector numbers; size_t bin_count{}; }; +// Input input_data() { Input in; int number_count; - do { - cout << "Enter number count: "; + cin >> number_count; + while (number_count < 1) { cin >> number_count; - } while (number_count < 1); + } - do { - cout << "Enter bucket: "; + cin >> in.bin_count; + while (in.bin_count < 1) { cin >> in.bin_count; - } while (in.bin_count < 1); - - cout << "\n"; + } in.numbers.resize(number_count); for (int i = 0; i < number_count; i++) { @@ -33,8 +34,9 @@ Input input_data() { return in; } +// int main() { - auto in = input_data(); - auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins); + auto in = input_data(); // + auto bins = make_histogram(in.numbers, in.bin_count); // + show_histogram_svg(bins); // SVG } diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..9913faa --- /dev/null +++ b/svg.cpp @@ -0,0 +1,58 @@ +#include "svg.h" +#include + +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, const string& text) { + cout << "" << text << "\n"; +} + +void svg_rect(double x, double y, double width, double height, + const string& stroke, const string& fill) { + cout << "\n"; +} + +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; + + size_t max_count = 0; + for (size_t count : bins) { + if (count > max_count) { + max_count = count; + } + } + + double BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH) / static_cast(max_count); + + svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); + + double top = 0; + for (size_t bin : bins) { + 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, "blue", "#aaaaff"); + top += BIN_HEIGHT; + } + + svg_end(); +} diff --git a/svg.h b/svg.h new file mode 100644 index 0000000..c771318 --- /dev/null +++ b/svg.h @@ -0,0 +1,11 @@ +#pragma once +#include +#include + +void svg_begin(double width, double height); +void svg_end(); +void svg_text(double left, double baseline, const std::string& text); +void svg_rect(double x, double y, double width, double height, + const std::string& stroke = "black", + const std::string& fill = "black"); +void show_histogram_svg(const std::vector& bins); diff --git a/Текстовый документ — копия (4).txt b/Текстовый документ — копия (4).txt deleted file mode 100644 index e69de29..0000000 diff --git a/Текстовый документ — копия (5).txt b/Текстовый документ — копия (5).txt deleted file mode 100644 index e69de29..0000000