code: выполнено задание 15 варианта

main
Ваше Имя 2 лет назад
Родитель 77a6c8beca
Сommit c034fd3589

2
.gitignore поставляемый

@ -13,3 +13,5 @@
/start /start
/main.o /main.o
/curl /curl
/main_copy.cpp
/marks1.txt

@ -1,32 +1,44 @@
//main.cpp -- the program gets number count, numbers and bin size, then builds a histogram. #include <curl/curl.h>
//Task 15 -- make a scale under the histogram.
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <curl/curl.h> #include <sstream>
#include <string>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
using namespace std; using namespace std;
struct Input { //data input
struct Input {
vector<double> numbers; vector<double> numbers;
size_t bin_count{}; size_t bin_count{};
size_t interval_task{}; size_t interval_task{};
}; };
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
size_t data_size = item_size * item_count;
Input //struct Input *i = (struct Input *)ctx;
input_data(istream& in, bool prompt) { //input data structure
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
buffer->write(reinterpret_cast<const char*>(items), data_size);
return data_size;
}
Input
input_data(istream& in, bool prompt)
{
if (prompt == false) { //prompt output if (prompt == false) { //prompt output
cerr.rdbuf(NULL); cerr.rdbuf(NULL);
} }
size_t number_count; size_t number_count;
cerr << "Enter number count: \n"; cerr << "Enter number count: \n";
cerr.flush();
in >> number_count; in >> number_count;
Input in_data_struct; Input in_data_struct;
@ -51,30 +63,51 @@ input_data(istream& in, bool prompt) {
} }
} }
Input
download(const string& address) {
stringstream buffer;
stringstream temp;
int CURL* curl = curl_easy_init();
main(int argc, char* argv[]) { if(curl) {
if (argc > 1) { CURLcode res;
CURL* curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
if (curl) { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_data);
res = curl_easy_perform(curl); curl_easy_setopt(curl, CURLOPT_HEADERDATA, &temp);
if (CURLE_OK == 0) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
if (CURLE_OK != 0) {
cerr << curl_easy_strerror(res); cerr << curl_easy_strerror(res);
exit(1); exit(1);
} }
cerr << temp.str();
curl_easy_cleanup(curl);
}
return input_data(buffer, false);
}
curl_easy_cleanup(curl); int
} main(int argc, char* argv[]) {
return 0; Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(cin, true);
} }
curl_global_init(CURL_GLOBAL_ALL); const auto bins = make_histogram(input.numbers, input.bin_count);
auto in = input_data(cin, true); //input data show_histogram_svg(bins, input.interval_task);
auto bins = make_histogram(in.numbers, in.bin_count); //calculating bin size for the histogram
show_histogram_svg(bins, in.interval_task); //histogram output in the format svg code //[OUTDATED]
//curl_global_init(CURL_GLOBAL_ALL);
// in = input_data(cin, true); //input data
//auto bins = make_histogram(in.numbers, in.bin_count); //calculating bin size for the histogram
//show_histogram_svg(bins, in.interval_task); //histogram output in the format svg code
return 0; return 0;
} }

@ -1,6 +1,13 @@
142 10
1 1 1 1 1 1 1 1 1 3
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3
3
3
4
5
5
5
3 3
6 6

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