From 5636df9530e75f1956ef47eac3eececb1e21235e Mon Sep 17 00:00:00 2001 From: MatusSV Date: Mon, 13 May 2024 11:23:29 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=20=E2=84=9616?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 18 ++++++++++++++++-- svg.cpp | 12 ++++++++++-- svg.h | 3 ++- svg_internal.h | 9 +++++++++ unittest.cbp | 3 +++ unittest.cpp | 16 ++++++++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 svg_internal.h diff --git a/main.cpp b/main.cpp index a7be46d..4960f04 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "histogram.h" //#include "text.h" #include "svg.h" @@ -8,6 +9,7 @@ using namespace std; struct Input { vector numbers; + vector colors; size_t bin_count{}; }; @@ -26,8 +28,20 @@ input_data() { cin >> in.numbers[i]; } - cerr << "Enter bins count: "; + cerr << "Enter bins count and colors: "; cin >> in.bin_count; + vector colors(in.bin_count); + in.colors.resize(in.bin_count); + + for (size_t i = 0; i < in.bin_count; i++) { + cin >> in.colors[i]; + bool check = check_color(in.colors[i]); + while (!check) { + cerr << "Incorrect input. Color doesn't contain # or has spaces." << endl; + cin >> in.colors[i]; + check = check_color(in.colors[i]); + } + } return in; } @@ -36,5 +50,5 @@ int main() Input in = input_data(); vector bins = make_histogram(in.numbers, in.bin_count); //show_histogram_text(bins, in.bin_count); - show_histogram_svg(bins); + show_histogram_svg(bins, in.colors); } diff --git a/svg.cpp b/svg.cpp index 1c62c07..386bb4f 100644 --- a/svg.cpp +++ b/svg.cpp @@ -5,6 +5,14 @@ using namespace std; +bool +check_color(string color) { + if (color[0]=='#'||color.find(' ')==(-1)) + return true; + else + return false; +} + void svg_text(double left, double baseline, string text) { cout << "