Сравнить коммиты
12 Коммитов
33fb81a6bb
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| ba3805c7cd | |||
| 438cacfdb1 | |||
| ed361dae03 | |||
| b9ccc72d62 | |||
| 9e1fbe8dbe | |||
| 54d52ef37d | |||
| d866ad8079 | |||
| 0bdf67a606 | |||
| 97036095fa | |||
| 0eb008b27e | |||
| 5bd52d8465 | |||
| 87617b312f |
@@ -33,12 +33,12 @@
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
68
main.cpp
68
main.cpp
@@ -1,4 +1,7 @@
|
||||
#include <curl/curl.h>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "histogram.h"
|
||||
@@ -11,31 +14,64 @@ struct Input {
|
||||
};
|
||||
|
||||
Input
|
||||
input_data() {
|
||||
input_data(istream& in, bool prompt) {
|
||||
size_t number_count;
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
if (prompt) {cerr << "Enter number count: ";};
|
||||
in >> number_count;
|
||||
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
cerr << "Enter numbers: ";
|
||||
Input in1;
|
||||
in1.numbers.resize(number_count);
|
||||
if (prompt) {cerr << "Enter numbers: ";};
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
in >> in1.numbers[i];
|
||||
}
|
||||
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> in.bin_count;
|
||||
|
||||
return in;
|
||||
if (prompt) {cerr << "Enter bin count: ";};
|
||||
in >> in1.bin_count;
|
||||
|
||||
return in1;
|
||||
}
|
||||
|
||||
int main()
|
||||
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<stringstream*>(ctx);
|
||||
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) {
|
||||
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 != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
exit(1);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
#include <curl/curl.h>
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
Input input;
|
||||
if (argc > 1) {
|
||||
input = download(argv[1]);
|
||||
} else {
|
||||
input = input_data(cin, true);
|
||||
}
|
||||
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="doctest.h" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
|
||||
Ссылка в новой задаче
Block a user