Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

77 строки
1.5 KiB
C++

#include <sstream>
#include <string>
#include <curl/curl.h>
#include <iostream>
#include <vector>
#include <cmath>
#include "histogram.h"
#include "svg.h"
using namespace std;
struct Input
{
vector<double> numbers;
size_t bin_count{};
};
Input
input_data(istream& in, bool prompt)
{
if(prompt)
cerr << "vvedite col-vo nomerov:";
size_t number_count;
in >> number_count;
Input rez;
if(prompt)
cerr << "vvedite nomera:";
rez.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++)
{
in >> rez.numbers[i];
}
if(prompt)
cerr << "vvedite col-vo corzin:";
in >> rez.bin_count;
return rez;
}
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);
if (res != 0)
{
cout << curl_easy_strerror(res);
exit(1);
}
curl_easy_cleanup(curl);
}
return input_data(buffer, false);
}
int
main(int argc, char* argv[])
{
Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(cin, true);
}
curl_global_init(CURL_GLOBAL_ALL);
bool prompt = false;
auto in = input_data(cin, prompt);
const auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
//show_histogram_text(bins, in.numbers, in.bin_count);
}