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

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

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

@ -13,3 +13,5 @@
/start
/main.o
/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.
//Task 15 -- make a scale under the histogram.
#include <curl/curl.h>
#include <iostream>
#include <vector>
#include <curl/curl.h>
#include <sstream>
#include <string>
#include "histogram.h"
#include "text.h"
#include "svg.h"
using namespace std;
struct Input { //data input
struct Input {
vector<double> numbers;
size_t bin_count{};
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
input_data(istream& in, bool prompt) { //input data structure
//struct Input *i = (struct Input *)ctx;
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
cerr.rdbuf(NULL);
}
size_t number_count;
cerr << "Enter number count: \n";
cerr.flush();
in >> number_count;
Input in_data_struct;
@ -51,30 +63,51 @@ input_data(istream& in, bool prompt) {
}
}
Input
download(const string& address) {
stringstream buffer;
stringstream temp;
int
main(int argc, char* argv[]) {
if (argc > 1) {
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
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_HEADERFUNCTION, write_data);
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);
exit(1);
}
cerr << temp.str();
curl_easy_cleanup(curl);
}
return 0;
return input_data(buffer, false);
}
int
main(int argc, char* argv[]) {
Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(cin, true);
}
curl_global_init(CURL_GLOBAL_ALL);
auto 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
const auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins, input.interval_task);
//[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;
}

@ -1,6 +1,13 @@
142
1 1 1 1 1 1 1 1 1
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
10
3
3
3
3
3
3
4
5
5
5
3
6

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