From a2d7dad6a809699b2e10a9e3d977e065e6fb8b24 Mon Sep 17 00:00:00 2001 From: victoriaCS Date: Sun, 1 Jun 2025 17:43:17 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3:=20=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20input=5Fd?= =?UTF-8?q?ata(std::istream&)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b6e0d66 --- /dev/null +++ b/main.cpp @@ -0,0 +1,73 @@ +#include +#define CURL_STATICLIB +#include +#include +#include "histogram.h" +#include "text.h" +#include "svg.h" + +using namespace std; + +struct Input { + vector numbers; + size_t bin_count{}; + size_t block_width{}; +}; + +Input input_data(istream& in_stream = cin, bool prompt = true) { + Input in; + size_t number_count; + + if (prompt) { + cerr << "Enter number count: "; + } + in_stream >> number_count; + + in.numbers.resize(number_count); + + if (prompt) { + cerr << "Enter " << number_count << " numbers: "; + } + for (size_t i = 0; i < number_count; i++) { + in_stream >> in.numbers[i]; + } + + if (prompt) { + cerr << "Enter bin count: "; + } + in_stream >> in.bin_count; + + return in; +} + +vector make_histogram(const vector& numbers, size_t bin_count) { + vector bins(bin_count, 0); + for (double num : numbers) { + size_t index = min(bin_count - 1, static_cast(num)); // пример + bins[index]++; + } + return bins; +} +} + +int main(int argc, char* argv[]) { + if (argc > 1) { + cout << "argc = " << argc << endl; + for (int i = 0; i < argc; ++i) { + cout << "argv[" << i << "] = \"" << argv[i] << "\"" << endl; + } + return 0; + } + + CURLcode res = curl_global_init(CURL_GLOBAL_ALL); + if (res != CURLE_OK) { + cerr << "cURL initialization failed: " << curl_easy_strerror(res) << endl; + return 1; + } + + auto in = input_data(); + auto bins = make_histogram(in.numbers, in.bin_count); + show_histogram_svg(bins, in.block_width); + + curl_global_cleanup(); +}