From 5be6275e3452ab503ba904650b0139c3a5cabbee Mon Sep 17 00:00:00 2001 From: GordiyevskikDA Date: Mon, 15 Apr 2024 14:51:21 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LABA1.cpp | 53 +++++++++++++++++++++++++++++++++------------------ LABA1.vcxproj | 6 ++---- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/LABA1.cpp b/LABA1.cpp index c9cf0a5..14ce3a0 100644 --- a/LABA1.cpp +++ b/LABA1.cpp @@ -4,6 +4,8 @@ #include "histogram.h" #include "text.h" #include +#include +#include using namespace std; @@ -67,35 +69,48 @@ struct Input { int NCharts = 0; }; -Input input_data() { +Input input_data(istream& instr, bool promt) { Input in; int VecSize = 0; - cin >> VecSize; + if (promt) { cout << "input num of marks\n"; } + instr >> VecSize; in.marks.resize(VecSize); + if (promt) { cout << "input num marks\n"; } for (int i = 0; i < VecSize; i++) { - cin >> in.marks[i]; + instr >> in.marks[i]; } - cin >> in.NCharts; + if (promt) { cout << "input num of charts\n"; } + instr >> in.NCharts; return in; }; +Input download(const string& address) { + stringstream buffer; + + CURL* curl = curl_easy_init(); + if (curl) { + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); + res = curl_easy_perform(curl); + curl_easy_cleanup(curl); + if (res != CURLE_OK) { + cout << curl_easy_strerror(res); + exit(1); + } + } + + return input_data(buffer, false); +} + int main(int argc, char* argv[]){ + Input input; if (argc > 1) { - CURL* curl = curl_easy_init(); - if (curl) { - CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, argv[1]); - res = curl_easy_perform(curl); - curl_easy_cleanup(curl); - if (res != CURLE_OK) { - cout << curl_easy_strerror(res); - exit(1); - } - } - return 0; + input = download(argv[1]); + } + else { + input = input_data(cin, true); } - Input in = input_data(); - vector chart = MakeHistogram(in.marks, in.NCharts); + vector chart = MakeHistogram(input.marks, input.NCharts); //show_histogram_text(in.marks, chart); - show_histogram_svg(in.marks, chart); + show_histogram_svg(input.marks, chart); } \ No newline at end of file diff --git a/LABA1.vcxproj b/LABA1.vcxproj index 9a14139..75da246 100644 --- a/LABA1.vcxproj +++ b/LABA1.vcxproj @@ -104,10 +104,8 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - C:\Users\gorda\OneDrive\Рабочий стол\LABA\LABA4\cs-lab34\curlic\include;%(AdditionalIncludeDirectories) - - - libcurl.dll.a;%(AdditionalHeaderUnitDependencies) + C:\Users\gorda\Desktop\laba\LABA4\newlaba\curlic\include;%(AdditionalIncludeDirectories) + libcurl.dll.a;%(AdditionalModuleDependencies) Console