From ee96c909490a19118099b67ea42b0029716f668e Mon Sep 17 00:00:00 2001 From: KozlovDanD Date: Sun, 15 Jun 2025 17:22:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92:18=20-=20=D1=82=D0=B5=D0=BA=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=20=D1=81=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 29 ++++++++++++++++++++++++----- marks.txt | 3 +++ svg.cpp | 26 +++++++++++--------------- svg.h | 2 +- 4 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 marks.txt diff --git a/main.cpp b/main.cpp index 43616e4..2fa5fb6 100644 --- a/main.cpp +++ b/main.cpp @@ -1,8 +1,13 @@ #include #include +#include #include "histogram.h" #include "text.h" #include "svg.h" +#include +#include + + using namespace std; struct Input @@ -39,12 +44,26 @@ int main() { Input in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - - double min, max; double bin_size = (max - min) / in.bin_count; - show_histogram_text(bins, in.bin_count, bin_size); - //show_histogram_svg(bins); -} + string decoration; + vector valid_decorations = {"none", "underline", "overline", "line-through"}; + + while (true) { + cerr << "Enter text decoration (none/underline/overline/line-through): "; + cin >> decoration; + + if (find(valid_decorations.begin(), valid_decorations.end(), decoration) + != valid_decorations.end()) { + break; + } + + cerr << "Please choose from: none, underline, overline, line-through" << "\n"; + } + + show_histogram_svg(bins, decoration); + + // show_histogram_text(bins, in.bin_count, bin_size); + } diff --git a/marks.txt b/marks.txt new file mode 100644 index 0000000..1f15d9e --- /dev/null +++ b/marks.txt @@ -0,0 +1,3 @@ +10 +3 3 4 4 4 4 4 5 5 5 3 +underline \ No newline at end of file diff --git a/svg.cpp b/svg.cpp index 86a7e0a..8e81788 100644 --- a/svg.cpp +++ b/svg.cpp @@ -20,10 +20,9 @@ svg_end() } void -svg_text(double left, double baseline, string text) +svg_text(double left, double baseline, string text, string decoration = "none") { - cout << "" << text << ""; - + cout << "" << text << "\n"; } void svg_rect(double x, double y, double width, double height, @@ -33,7 +32,7 @@ void svg_rect(double x, double y, double width, double height, } void -show_histogram_svg(const vector& bins) +show_histogram_svg(const vector& bins, const string& text_decoration) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; @@ -66,17 +65,14 @@ for (size_t bin : bins) double top = 0; for (size_t bin : bins) { if (bin == max) { - const double bin_width = BLOCK_WIDTH * bin; - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, MAX_WIDTH, BIN_HEIGHT); - top += BIN_HEIGHT; - } - else{ - const 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); - top += BIN_HEIGHT; - } + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin), text_decoration); + svg_rect(TEXT_WIDTH, top, MAX_WIDTH, BIN_HEIGHT); + top += BIN_HEIGHT; + } else { + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin), text_decoration); + svg_rect(TEXT_WIDTH, top, BLOCK_WIDTH, BIN_HEIGHT); + top += BIN_HEIGHT; + } } svg_end(); } diff --git a/svg.h b/svg.h index 8dd3117..b947167 100644 --- a/svg.h +++ b/svg.h @@ -5,7 +5,7 @@ #include #include -void show_histogram_svg(const std::vector& bins); +void show_histogram_svg(const std::vector& bins, const std::string& text_decoration = "none"); #endif // SVG_H_INCLUDED