Сравнить коммиты
6 Коммитов
42e7693952
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| f5337ca7f3 | |||
| cdb0ed80e5 | |||
| 5df161bc2b | |||
| 0ab4123e0d | |||
| 544630f381 | |||
| 839f3e9942 |
@@ -1,16 +1,21 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
bool
|
bool
|
||||||
find_minmax(const std::vector<double>& numbers, double& min, double& max) {
|
find_minmax(std::vector<double> numbers, double& min, double& max) {
|
||||||
|
if(numbers.size() == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
for(double x : numbers){
|
for (double x : numbers) {
|
||||||
if(x<min){
|
if (x < min) {
|
||||||
min=x;
|
min = x;
|
||||||
}
|
}
|
||||||
if(x>max){
|
else if (x > max)
|
||||||
max=x;
|
{
|
||||||
|
max = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
std::vector<size_t>
|
std::vector<size_t>
|
||||||
make_histogram(const std::vector<double>& numbers,size_t bin_count){
|
make_histogram(const std::vector<double>& numbers,size_t bin_count){
|
||||||
|
|||||||
60
main.cpp
60
main.cpp
@@ -1,31 +1,69 @@
|
|||||||
|
#include <curl/curl.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
struct Input {
|
struct Input {
|
||||||
vector<double> numbers;
|
vector<double> numbers;
|
||||||
size_t bin_count{};
|
size_t bin_count{};
|
||||||
};
|
};
|
||||||
Input
|
Input
|
||||||
input_data(){
|
input_data(istream& in,bool promt = false) {
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
|
if (promt)
|
||||||
cerr << "Number_count: ";
|
cerr << "Number_count: ";
|
||||||
cin >> number_count;
|
in >> number_count;
|
||||||
Input in;
|
Input im;
|
||||||
in.numbers.resize(number_count);
|
im.numbers.resize(number_count);
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
cin >> in.numbers[i];
|
in >> im.numbers[i];
|
||||||
}
|
}
|
||||||
|
if (promt)
|
||||||
cerr << "Enter bin_count: ";
|
cerr << "Enter bin_count: ";
|
||||||
cin >> in.bin_count;
|
in >> im.bin_count;
|
||||||
return in;
|
return im;
|
||||||
}
|
}
|
||||||
int
|
size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx){
|
||||||
main() {
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||||
auto in = input_data();
|
size_t data_size = item_size * item_count;
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input download(const string& address) {
|
||||||
|
stringstream buffer;
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if(curl) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
|
CURLcode res = curl_easy_perform(curl);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
if(res != 0){
|
||||||
|
cerr << curl_easy_strerror(res);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input_data(buffer, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
|
Input input;
|
||||||
|
if (argc > 1) {
|
||||||
|
input = download(argv[1]);
|
||||||
|
} else {
|
||||||
|
input = input_data(cin, true);
|
||||||
|
}
|
||||||
|
auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
show_histogram_svg(bins);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user