Доделал программу и вариант
Этот коммит содержится в:
@@ -39,12 +39,14 @@
|
|||||||
<vector>
|
<vector>
|
||||||
<string>
|
<string>
|
||||||
|
|
||||||
1685952174 source:c:\users\stepa\desktop\lab04\lab04\main.cpp
|
1685953545 source:c:\users\stepa\desktop\lab04\lab04\main.cpp
|
||||||
<iostream>
|
<iostream>
|
||||||
"vector"
|
"vector"
|
||||||
"svg.h"
|
"svg.h"
|
||||||
"histogram.h"
|
"histogram.h"
|
||||||
"curl/curl.h"
|
"curl/curl.h"
|
||||||
|
<sstream>
|
||||||
|
<string>
|
||||||
|
|
||||||
1685361112 c:\users\stepa\desktop\lab04\lab04\curl\include\curl\curl.h
|
1685361112 c:\users\stepa\desktop\lab04\lab04\curl\include\curl\curl.h
|
||||||
"curlver.h"
|
"curlver.h"
|
||||||
|
|||||||
@@ -7,9 +7,14 @@
|
|||||||
<Cursor1 position="29" topLine="0" />
|
<Cursor1 position="29" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="890" topLine="23" />
|
<Cursor1 position="0" topLine="3" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1800" topLine="59" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|||||||
134
main.cpp
134
main.cpp
@@ -1,62 +1,120 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "vector"
|
#include <vector>
|
||||||
#include "svg.h"
|
#include <conio.h>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "curl/curl.h"
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
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(istream& inn, bool promt) {
|
input_data(istream& in, bool promt)
|
||||||
|
{
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
if (promt)
|
if (promt)
|
||||||
{
|
{
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
}
|
}
|
||||||
cin >> number_count;
|
in >> number_count;
|
||||||
Input in;
|
|
||||||
in.numbers.resize(number_count);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
Input ik;
|
||||||
cin >> in.numbers[i];
|
ik.numbers.resize(number_count);
|
||||||
}
|
for (size_t i = 0; i < number_count; i++)
|
||||||
if (promt)
|
|
||||||
{
|
{
|
||||||
cerr << "Enter bins number: ";
|
in >> ik.numbers[i];
|
||||||
}
|
}
|
||||||
cin >> in.bin_count;
|
if (promt)
|
||||||
return in;
|
{
|
||||||
|
cerr << "Enter bin count: ";
|
||||||
|
}
|
||||||
|
in>> ik.bin_count;
|
||||||
|
return ik;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
{
|
||||||
|
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;
|
||||||
|
double file_size;
|
||||||
|
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[])
|
||||||
|
{
|
||||||
|
Input input;
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
CURL *curl = curl_easy_init();
|
input = download(argv[3]);
|
||||||
if(curl)
|
int bins_cnt = atoi(argv[2]);
|
||||||
{
|
string check = typeid(atoi(argv[2])).name();
|
||||||
CURLcode res;
|
if(check != "int"){
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
cout << "Ââåäèòå ÷èñëî ïîñëå -bins";
|
||||||
res = curl_easy_perform(curl);
|
return 0;
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
if (res != CURLE_OK){
|
|
||||||
cout << curl_easy_strerror;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
const auto bins = make_histogram(input.numbers, bins_cnt);
|
||||||
|
show_histogram_svg(bins);
|
||||||
|
|
||||||
}
|
}
|
||||||
auto in = input_data(cin, true);
|
else
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
{
|
||||||
//show_histogram_text(bins, in.bin_count);
|
input = input_data(cin, true);
|
||||||
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
show_histogram_svg(bins);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
Input input;
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
int bins_cnt = atoi(argv[2]);
|
||||||
|
input = download(argv[3]);
|
||||||
|
const auto bins = make_histogram(input.numbers, bins_cnt);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
input = input_data(cin, true);
|
||||||
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user