code: итоговая версия программы без варианта
Этот коммит содержится в:
@@ -2,9 +2,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
@@ -13,61 +16,76 @@ struct Input {
|
|||||||
size_t bin_count{};
|
size_t bin_count{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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<stringstream*>(ctx);
|
||||||
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data(istream& in,bool promt)
|
input_data(istream& in, bool prompt)
|
||||||
{
|
{
|
||||||
if(promt){
|
if(prompt)
|
||||||
|
|
||||||
size_t number_count;
|
|
||||||
cerr << "count=";
|
cerr << "count=";
|
||||||
cin >> number_count;
|
size_t number_count;
|
||||||
|
in >> number_count;
|
||||||
|
|
||||||
Input rez;
|
Input rez;
|
||||||
|
|
||||||
|
if(prompt)
|
||||||
|
cerr << "numbers= ";
|
||||||
rez.numbers.resize(number_count);
|
rez.numbers.resize(number_count);
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++)
|
||||||
cin >> rez.numbers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
cerr << "bin_count= ";
|
|
||||||
cin >> rez.bin_count;
|
|
||||||
|
|
||||||
return rez;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
size_t number_count;
|
in >> rez.numbers[i];
|
||||||
cerr << "count=";
|
|
||||||
cin >> number_count;
|
|
||||||
|
|
||||||
Input rez;
|
|
||||||
|
|
||||||
rez.numbers.resize(number_count);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
|
||||||
cin >> rez.numbers[i];
|
|
||||||
}
|
}
|
||||||
|
if(prompt)
|
||||||
cerr << "bin_count= ";
|
cerr << "bin_count= ";
|
||||||
cin >> rez.bin_count;
|
in >> rez.bin_count;
|
||||||
|
|
||||||
return rez;
|
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());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
{ if (argc > 1) {
|
|
||||||
cout<<argc;
|
|
||||||
for(int i=0;i<argc;i++)
|
|
||||||
cout << "argv["<<i<<"]="<<argv[i];
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
bool promt = true;
|
|
||||||
auto in = input_data(cin,promt);
|
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
||||||
double ttt=0.0;
|
double ttt=0.0;
|
||||||
show_histogram_svg(bins,ttt);
|
show_histogram_svg(bins,ttt);
|
||||||
/* show_histogram_text(bins, in.bin_count);*/
|
/* show_histogram_text(bins, in.bin_count);*/
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user