diff --git a/histogram.cpp b/histogram.cpp index 165dc76..fddb2cc 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -27,7 +27,7 @@ find_minmax(const vector& numbers, double& min, double& max) { return flag; } -vector make_histogram(const vector numbers, size_t bin_count, bool& flag){ +vector make_histogram(const vector numbers, size_t bin_count){ vector bins(bin_count); double max, min = 0; find_minmax(numbers, min, max); diff --git a/histogram.h b/histogram.h index f014ed2..aab82b8 100644 --- a/histogram.h +++ b/histogram.h @@ -4,6 +4,6 @@ #include std::vector -make_histogram(const std::vector numbers, size_t bin_count, bool& flag); +make_histogram(const std::vector numbers, size_t bin_count); #endif // HISTOGRAM_H_INCLUDED diff --git a/main.cpp b/main.cpp index 8236bb4..c522121 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,8 @@ #include #include #include +#include + using namespace std; @@ -21,9 +23,9 @@ struct Input { Input input_data(istream& in, bool prompt) { - if (prompt == true) { + if (prompt == true){ size_t number_count; - cerr << "amount of numbers"; + cerr << "input number count"; in >> number_count; Input inn; inn.numbers.resize(number_count); @@ -34,14 +36,13 @@ input_data(istream& in, bool prompt) { } size_t bin_count; -cerr << "amount of baskets"; +cerr << "input amount of bins"; in >> inn.bin_count; return inn; } - - else if (prompt == false) { + else { size_t number_count; - cout << "amount of numbers"; + cout << "input number count"; in >> number_count; Input inn; inn.numbers.resize(number_count); @@ -51,36 +52,59 @@ return inn; in >> inn.numbers[i]; } -size_t bin_count; -cout << "input baskets"; -in >> inn.bin_count; -return inn; + size_t bin_count; + cout << "input amount of bins"; + in >> inn.bin_count; + return inn; } } +static size_t +write_data(void* items, size_t item_size, size_t item_count, void* ctx) { + size_t data_size = item_size * item_count; + stringstream* buffer = reinterpret_cast(ctx); + buffer->write(reinterpret_cast(items), data_size); + return data_size; +} + +Input +download(const string& address) { + stringstream buffer; + CURL* curl = curl_easy_init(); + if(curl) + { + CURLcode res; + const char* res2; + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); + res = curl_easy_perform(curl); + if (res!=0) + { + res2=curl_easy_strerror(res); + cout< 1) { - if(curl) { - CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, "http://uit.mpei.ru/study/courses/cs/lab03/marks.txt"); - res = curl_easy_perform(curl); - curl_easy_cleanup(curl); - cout << res; - return 0; - } + in = download(argv[1]); + } else { + in = input_data(cin, true); } - - bool flag; - 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); + auto bins = make_histogram(in.numbers, in.bin_count); + auto procent = make_histogram_proc(in.numbers, in.bin_count, bins); show_histogram_svg(bins, procent); return 0;