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

74 строки
1.9 KiB
C++

#include <iostream>
#include <vector>
#include <string>
#include "histogram.h"
//#include "text.h"
#include "svg.h"
#include <curl/curl.h>
using namespace std;
struct Input {
vector<double> numbers;
vector<string> colors;
size_t bin_count{};
};
Input
input_data(istream& in_stream,bool prompt) {
size_t number_count;
Input in;
if (prompt) cerr << "Enter number count: ";
in_stream >> number_count;
vector<double> numbers(number_count);
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
in_stream >> in.numbers[i];
}
if (prompt) cerr << "Enter bins count and colors: ";
in_stream >> in.bin_count;
vector<string> colors(in.bin_count);
in.colors.resize(in.bin_count);
for (size_t i = 0; i < in.bin_count; i++) {
in_stream >> in.colors[i];
bool check = check_color(in.colors[i]);
while (!check) {
if (prompt) cerr << "Incorrect input. Color doesn't contain # or has spaces." << endl;
in_stream >> in.colors[i];
check = check_color(in.colors[i]);
}
}
return in;
}
int main(int argc, char* argv[])
{
if (argc > 1)
{
//cerr<<argc<<endl;
//for (size_t i = 0; argv[i]; i++) cerr<<argv[i]<<endl;
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;
}
curl_global_init(CURL_GLOBAL_ALL);
auto in = input_data(cin,true);
vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
//show_histogram_text(bins, in.bin_count);
show_histogram_svg(bins, in.colors);
}