From 0b4c300e968af4cfb1bfaeea990aef25ea269e13 Mon Sep 17 00:00:00 2001 From: "Ivan (BeloziorovIA)" Date: Mon, 19 May 2025 15:32:54 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JIa6a_3.cbp | 13 +++++++++++++ JIa6a_3.depend | 36 ++++++++++++++++++++++++++++++++++++ main.cpp | 14 +++++++++++++- svg.cpp | 14 +++++++++++++- svg.h | 5 ++++- unittest.cbp | 4 ++++ 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 JIa6a_3.depend diff --git a/JIa6a_3.cbp b/JIa6a_3.cbp index dee3f23..1ab1cef 100644 --- a/JIa6a_3.cbp +++ b/JIa6a_3.cbp @@ -32,7 +32,20 @@ + + + + + + + + + + diff --git a/JIa6a_3.depend b/JIa6a_3.depend new file mode 100644 index 0000000..73cba93 --- /dev/null +++ b/JIa6a_3.depend @@ -0,0 +1,36 @@ +# depslib dependency file v1.0 +1746405872 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\histogram.cpp + "histogram.h" + + +1746351454 c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\histogram.h + + +1747656559 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\main.cpp + + + + + + "histogram.h" + "text.h" + "svg.h" + +1746352309 c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\text.h + + +1747656828 c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\svg.h + + + +1747656828 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\svg.cpp + + "svg.h" + + + +1746352405 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\text.cpp + "text.h" + + + diff --git a/main.cpp b/main.cpp index ffa2df8..71381c5 100644 --- a/main.cpp +++ b/main.cpp @@ -36,15 +36,27 @@ Input input_data(){ return stct; } +//Ввод параметров черточки +void dash_param(size_t& length_dsh, size_t& length_invl){ + cerr << "Enter length dash "; + cin >> length_dsh; + cerr << "Enter length interval "; + cin >> length_invl; +} + int main() { //Ввод массива и количества корзин Input in = input_data(); + //Ввод длины черты и интервала между чертами + size_t length_dash, length_interval; + dash_param(length_dash, length_interval); + //Создание вектора bins для гистограммы vector bins = make_histogram(in.Numbers, in.bin_count); //Вывод гистограммы - show_histogram_svg(bins); + show_histogram_svg(bins, length_dash, length_interval); //show_histogram_text(bins); return 0; diff --git a/svg.cpp b/svg.cpp index 093582e..7411ed1 100644 --- a/svg.cpp +++ b/svg.cpp @@ -23,7 +23,7 @@ void svg_text(double left, double baseline, std::string text) std::cout << "" << text << ""; } -void show_histogram_svg(const std::vector& bins) +void show_histogram_svg(const std::vector& bins, const size_t length_dsh, const size_t length_invl) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; @@ -43,6 +43,8 @@ void show_histogram_svg(const std::vector& bins) if (bin > max_bin) max_bin = bin; } + std::string dash_pattern = std::to_string(length_dsh) + " " + std::to_string(length_invl); + if (max_bin * BLOCK_WIDTH > MAX_AVAIL_WIDTH) { // масштабный коэффициент @@ -55,6 +57,7 @@ void show_histogram_svg(const std::vector& bins) svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + svg_line(0, top + BIN_HEIGHT, IMAGE_WIDTH, top + BIN_HEIGHT, dash_pattern); top += BIN_HEIGHT; } } @@ -66,6 +69,7 @@ void show_histogram_svg(const std::vector& bins) const double bin_width = BLOCK_WIDTH * bin; svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + svg_line(0, top + BIN_HEIGHT, IMAGE_WIDTH, top + BIN_HEIGHT, dash_pattern); top += BIN_HEIGHT; } } @@ -77,3 +81,11 @@ void svg_rect(double x, double y, double width, double height, std::string strok { std::cout << ""; } + + + +//защита +void svg_line(double x1, double y1, double x2, double y2, const std::string stroke_dasharray){ + std::cout << "\n"; +} diff --git a/svg.h b/svg.h index 2340485..3182463 100644 --- a/svg.h +++ b/svg.h @@ -5,8 +5,11 @@ void svg_begin(double width, double height); void svg_end(); -void show_histogram_svg(const std::vector& bins); +void show_histogram_svg(const std::vector& bins, const size_t length_dsh, const size_t length_invl); void svg_text(double left, double baseline, std::string text); void svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black"); +//защита +void svg_line(double x1, double y1, double x2, double y2, const std::string stroke_dasharray); + #endif // SVG_H_INCLUDED diff --git a/unittest.cbp b/unittest.cbp index 6da4486..379d0a2 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,6 +31,10 @@ + + + +