From d5a9d7892466eb5756e1e9449bc5a075fd0ca40c Mon Sep 17 00:00:00 2001 From: EfremovSI Date: Sat, 18 May 2024 11:47:04 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=81=D0=B5=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + hist_proc.cpp | 1 + histogram.cpp | 19 ++++++++++++++----- histogram.h | 2 +- main.cpp | 32 +++++++++++++++++++++++++++++--- unittest4var.cpp | 5 +++++ 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 4c7473d..0a4fc6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /bin /obj +/curl diff --git a/hist_proc.cpp b/hist_proc.cpp index 6f825d9..978a7d5 100644 --- a/hist_proc.cpp +++ b/hist_proc.cpp @@ -1,6 +1,7 @@ #include #include #include "hist_proc.h" +#include "hist_proc_internal.h" using namespace std; vector make_histogram_proc(const vector numbers, size_t bin_count, vector bins){ vector procent(bin_count); diff --git a/histogram.cpp b/histogram.cpp index 48aa578..165dc76 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -4,11 +4,17 @@ using namespace std; -static void +bool find_minmax(const vector& numbers, double& min, double& max) { - min = numbers[0]; - max = numbers[0]; - for (double x : numbers) { + bool flag; + if (numbers.size() == 0){ + flag=false; + + } + else { + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { if (x < min) { min = x; } @@ -18,7 +24,10 @@ find_minmax(const vector& numbers, double& min, double& max) { } } -vector make_histogram(const vector numbers, size_t bin_count){ + return flag; +} + +vector make_histogram(const vector numbers, size_t bin_count, bool& flag){ vector bins(bin_count); double max, min = 0; find_minmax(numbers, min, max); diff --git a/histogram.h b/histogram.h index aab82b8..f014ed2 100644 --- a/histogram.h +++ b/histogram.h @@ -4,6 +4,6 @@ #include std::vector -make_histogram(const std::vector numbers, size_t bin_count); +make_histogram(const std::vector numbers, size_t bin_count, bool& flag); #endif // HISTOGRAM_H_INCLUDED diff --git a/main.cpp b/main.cpp index 23d3835..1c7a6fc 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,7 @@ #include "histogram.h" #include #include - +#include using namespace std; @@ -20,19 +20,42 @@ struct Input { Input -input_data(istream& in) { +input_data(istream& in, bool prompt) { + if (prompt == true) { + size_t number_count; + cerr << "amount of numbers"; + in >> number_count; + Input inn; + inn.numbers.resize(number_count); + vector numbers(number_count); + cerr << "input numbers"; + for (size_t i = 0; i < number_count; i++) { + in >> inn.numbers[i]; + } + +size_t bin_count; +cerr << "amount of baskets"; +in >> inn.bin_count; +return inn; + } + + else if (prompt == false) { size_t number_count; + cout << "amount of numbers"; in >> number_count; Input inn; inn.numbers.resize(number_count); vector numbers(number_count); + cout << "input numbers"; for (size_t i = 0; i < number_count; i++) { in >> inn.numbers[i]; } size_t bin_count; +cout << "input baskets"; in >> inn.bin_count; return inn; + } } @@ -40,8 +63,11 @@ return inn; int main() { + curl_global_init(CURL_GLOBAL_ALL); bool flag; - auto inn = input_data(cin); + bool prompt; + prompt = true; + auto inn = input_data(cin, prompt); auto bins = make_histogram(inn.numbers, inn.bin_count, flag); auto procent = make_histogram_proc(inn.numbers, inn.bin_count, bins); show_histogram_svg(bins, procent); diff --git a/unittest4var.cpp b/unittest4var.cpp index 17a2b23..327f54b 100644 --- a/unittest4var.cpp +++ b/unittest4var.cpp @@ -9,4 +9,9 @@ TEST_CASE("distinct positive numbers") { CHECK(procent[0] == 33); CHECK(procent[1] == 33); CHECK(procent[2] == 34); + + procent = make_histogram_proc({1}, 3, {1, 0, 0}); + CHECK(procent[0] == 100); + CHECK(procent[1] == 0); + CHECK(procent[2] == 0); }