From 33fb81a6bbbc7d4f4f62ae112f99cfb69af08faa Mon Sep 17 00:00:00 2001 From: KireevYP Date: Sun, 21 Apr 2024 23:22:24 +0300 Subject: [PATCH 1/4] =?UTF-8?q?ind:=20=D0=B8=D0=BD=D0=B4=D0=B8=D0=B2=D0=B8?= =?UTF-8?q?=D0=B4=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1st try.cbp | 6 ++++++ svg.cpp | 15 ++++++++++++++- unittest.cbp | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/1st try.cbp b/1st try.cbp index fb679d6..cd26766 100644 --- a/1st try.cbp +++ b/1st try.cbp @@ -32,7 +32,13 @@ + + + + + diff --git a/svg.cpp b/svg.cpp index 2e82799..b6122c9 100644 --- a/svg.cpp +++ b/svg.cpp @@ -41,6 +41,7 @@ show_histogram_svg(const vector& bins) { const auto BLOCK_WIDTH = 10; const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH); + double sum = 0; double max_count = (bins[0] * BLOCK_WIDTH); for (double bin: bins){ if ((bin * BLOCK_WIDTH) > max_count) { @@ -48,12 +49,24 @@ show_histogram_svg(const vector& bins) { } } + for (double bin: bins){ + sum = sum + (MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count)); + } + + double avg_width = sum/bins.size(); + + svg_begin(400, 300); double top = 0; for (double bin : bins) { const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa"); + if (bin_width > avg_width){ + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#e71320"); + } + else { + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#2fe713"); + } top += BIN_HEIGHT; } svg_end(); diff --git a/unittest.cbp b/unittest.cbp index 7f9621b..c1d124d 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,6 +31,8 @@ + + From 87617b312fb978767c7eb9fdb79d49f120fb69d8 Mon Sep 17 00:00:00 2001 From: KireevYP Date: Mon, 6 May 2024 14:30:29 +0300 Subject: [PATCH 2/4] =?UTF-8?q?code:=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=20in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1st try.cbp | 2 ++ main.cpp | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/1st try.cbp b/1st try.cbp index cd26766..2df892d 100644 --- a/1st try.cbp +++ b/1st try.cbp @@ -33,12 +33,14 @@ + + diff --git a/main.cpp b/main.cpp index c8a6784..08c7870 100644 --- a/main.cpp +++ b/main.cpp @@ -11,22 +11,22 @@ struct Input { }; Input -input_data() { +input_data(istream& in) { size_t number_count; cerr << "Enter number count: "; - cin >> number_count; + in >> number_count; - Input in; - in.numbers.resize(number_count); + Input in1; + in1.numbers.resize(number_count); cerr << "Enter numbers: "; for (size_t i = 0; i < number_count; i++) { - cin >> in.numbers[i]; + in >> in1.numbers[i]; } cerr << "Enter bin count: "; - cin >> in.bin_count; + in >> in1.bin_count; - return in; + return in1; } int main() @@ -34,7 +34,7 @@ int main() const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; - auto in = input_data(); + auto in = input_data(cin); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins); return 0; From 5bd52d8465102cfc90606bcd533a9f53e847ba53 Mon Sep 17 00:00:00 2001 From: KireevYP Date: Mon, 6 May 2024 14:37:31 +0300 Subject: [PATCH 3/4] code: prompt --- main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 08c7870..6670151 100644 --- a/main.cpp +++ b/main.cpp @@ -11,19 +11,19 @@ struct Input { }; Input -input_data(istream& in) { +input_data(istream& in, bool prompt) { size_t number_count; - cerr << "Enter number count: "; + if (prompt) {cerr << "Enter number count: ";} in >> number_count; Input in1; in1.numbers.resize(number_count); - cerr << "Enter numbers: "; + if (prompt) {cerr << "Enter numbers: ";} for (size_t i = 0; i < number_count; i++) { in >> in1.numbers[i]; } - cerr << "Enter bin count: "; + if (prompt) {cerr << "Enter bin count: ";} in >> in1.bin_count; return in1; @@ -33,8 +33,9 @@ int main() { const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + bool prompt = true; - auto in = input_data(cin); + auto in = input_data(cin, prompt); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins); return 0; From 0eb008b27e72ffd7e27154c9b0aa598ff8950add Mon Sep 17 00:00:00 2001 From: KireevYP Date: Sat, 18 May 2024 11:21:13 +0300 Subject: [PATCH 4/4] =?UTF-8?q?lib:=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20curl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/main.cpp b/main.cpp index 6670151..c286ecd 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include