Сравнить коммиты

...

4 Коммитов

Автор SHA1 Сообщение Дата
Oleg 21a6cf40ce lab04
2 лет назад
Oleg 8778770f4e code: error
2 лет назад
Oleg ae07c72c0b Работа с cURL
2 лет назад
Oleg f255d27719 arg
2 лет назад

@ -2,29 +2,24 @@
<CodeBlocks_layout_file> <CodeBlocks_layout_file>
<FileVersion major="1" minor="0" /> <FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" /> <ActiveTarget name="Debug" />
<File name="text.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="13" zoom_2="0"> <File name=".gitignore" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="15" zoom_2="0">
<Cursor>
<Cursor1 position="69" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="16" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="175" topLine="0" /> <Cursor1 position="19" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="15" zoom_2="0"> <File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="15" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="909" topLine="23" /> <Cursor1 position="867" topLine="18" />
</Cursor> </Cursor>
</File> </File>
<File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="20" zoom_2="0"> <File name="svg.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="17" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="168" topLine="0" /> <Cursor1 position="18" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="svg.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="17" zoom_2="0"> <File name="histogram.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="16" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="18" topLine="0" /> <Cursor1 position="175" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="17" zoom_2="0"> <File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="17" zoom_2="0">
@ -32,14 +27,19 @@
<Cursor1 position="566" topLine="0" /> <Cursor1 position="566" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name=".gitignore" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="15" zoom_2="0"> <File name="text.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="11" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="19" topLine="0" /> <Cursor1 position="448" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="text.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="11" zoom_2="0"> <File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="20" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="448" topLine="0" /> <Cursor1 position="168" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="13" zoom_2="0">
<Cursor>
<Cursor1 position="69" topLine="0" />
</Cursor> </Cursor>
</File> </File>
</CodeBlocks_layout_file> </CodeBlocks_layout_file>

@ -1,9 +1,10 @@
#include <math.h> #include <math.h>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <sstream>
#include <string.h> #include <string.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <string>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
@ -18,17 +19,23 @@ struct Input {
}; };
Input Input
input_data(istream& in) { input_data(istream& in,bool prompt) {
string a, b, c;
if(prompt== true){
a = "Enter number count:";
b = "Enter numbers:";
c = "Enter bin count:";
}
size_t number_count; size_t number_count;
cerr << "Enter number count: "; cerr << a;
in >> number_count; in >> number_count;
Input on; Input on;
on.numbers.resize(number_count); on.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) { for (size_t i = 0; i < number_count; i++) {
cerr << "Enter number " << i+1 << ": "; cerr << b << i+1 << ": ";
in >> on.numbers[i];} in >> on.numbers[i];}
cerr << "Enter bin count: "; cerr << c;
in >> on.bin_count; in >> on.bin_count;
on.n = 0; on.n = 0;
@ -42,14 +49,42 @@ input_data(istream& in) {
return on; return on;
} }
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;
res = curl_easy_perform(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);
if(res != CURLE_OK){
cerr << curl_easy_strerror(res);
exit(1);}
curl_easy_cleanup(curl);}
return input_data(buffer, false);
}
int main() int main(int argc, char* argv[]){
{ Input input;
curl_global_init(CURL_GLOBAL_ALL); if (argc > 1) {
input = download(argv[1]);}
else {
input = input_data(cin, true);}
auto in = input_data(cin); const auto bins = make_histogram(input.numbers, input.bin_count);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);
return 0; return 0;
} }

Загрузка…
Отмена
Сохранить