Сравнить коммиты
8 Коммитов
a5aeaa0976
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| b2ec2b1bd9 | |||
| 6ebc5ea258 | |||
| 75c4b02d7f | |||
| 23703c408c | |||
| beeb53983e | |||
| 960722ab48 | |||
| 328a9f28bb | |||
| ad6006ab90 |
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -1,2 +1,3 @@
|
||||
/bin
|
||||
/obj
|
||||
/curl
|
||||
12
Lab1.cbp
12
Lab1.cbp
@@ -14,9 +14,12 @@
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
<Add directory="include" />
|
||||
<Add directory="curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-static-libstdc++" />
|
||||
<Add library="curl/lib/libcurl.dll.a" />
|
||||
<Add directory="curl/lib" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
@@ -36,7 +39,14 @@
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add directory="D:/Projects_Code_Blocks/2_halfYear/Lab4/Lab1/curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-static-libstdc++" />
|
||||
<Add option="-static-libgcc" />
|
||||
<Add library="curl/lib/libcurl.dll.a" />
|
||||
<Add directory="D:/Projects_Code_Blocks/2_halfYear/Lab4/Lab1/curl/lib" />
|
||||
</Linker>
|
||||
<Unit filename="histogram.cpp">
|
||||
<Option target="Debug" />
|
||||
</Unit>
|
||||
@@ -47,8 +57,6 @@
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="prot.cpp" />
|
||||
<Unit filename="prot.h" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp">
|
||||
|
||||
54
main.cpp
54
main.cpp
@@ -1,9 +1,11 @@
|
||||
#include <curl/curl.h>
|
||||
|
||||
using namespace std;
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
struct Input {
|
||||
std::vector<double> numbers;
|
||||
@@ -11,37 +13,73 @@ struct Input {
|
||||
};
|
||||
|
||||
Input input_data(istream& in, bool promt);
|
||||
Input download(const string& address);
|
||||
|
||||
int main()
|
||||
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);
|
||||
}
|
||||
|
||||
Input in = input_data(cin);
|
||||
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
||||
|
||||
|
||||
std::vector<size_t> bins = make_histogram(input.numbers, input.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Input
|
||||
download(const string& address) {
|
||||
stringstream buffer;
|
||||
CURL* curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, address);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, input_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res!=0){
|
||||
cout << curl_easy_strerror(res) << endl;
|
||||
exit(1);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
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<char*>(items), data_size);
|
||||
return data_size;
|
||||
}
|
||||
|
||||
Input input_data(istream& in, bool promt) {
|
||||
|
||||
Input input_struct;
|
||||
size_t countOfNumbers;
|
||||
if(promt){cerr << "Input your count of numbers:\n";}
|
||||
|
||||
cin >> countOfNumbers;
|
||||
in >> countOfNumbers;
|
||||
|
||||
input_struct.numbers.resize(countOfNumbers);
|
||||
if(promt){cerr << "Input numbers:\n";}
|
||||
for (int i = 0; i < countOfNumbers; i++) {
|
||||
if(promt){cerr << i << ":" << endl;}
|
||||
cin >> input_struct.numbers[i];
|
||||
in >> input_struct.numbers[i];
|
||||
}
|
||||
if(promt){
|
||||
cerr << endl;
|
||||
cerr << "Input bin count:\n";
|
||||
}
|
||||
|
||||
cin >> input_struct.bin_count;
|
||||
in >> input_struct.bin_count;
|
||||
|
||||
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user