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 <curl/curl.h> +#include <sstream> +#include <string> 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 <double> chart = MakeHistogram(in.marks, in.NCharts); + vector <double> 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 @@ <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> - <AdditionalIncludeDirectories>C:\Users\gorda\OneDrive\Рабочий стол\LABA\LABA4\cs-lab34\curlic\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalModuleDependencies> - </AdditionalModuleDependencies> - <AdditionalHeaderUnitDependencies>libcurl.dll.a;%(AdditionalHeaderUnitDependencies)</AdditionalHeaderUnitDependencies> + <AdditionalIncludeDirectories>C:\Users\gorda\Desktop\laba\LABA4\newlaba\curlic\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalModuleDependencies>libcurl.dll.a;%(AdditionalModuleDependencies)</AdditionalModuleDependencies> </ClCompile> <Link> <SubSystem>Console</SubSystem>