lab4 индивидуальный вариант 4
Этот коммит содержится в:
@@ -9,13 +9,14 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <ctype.h>
|
||||||
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_data(istream& in,bool prompt)
|
Input input_data(istream& in,bool prompt, int bins_cht)
|
||||||
{
|
{
|
||||||
Input in_data;
|
Input in_data;
|
||||||
int number_count;
|
int number_count;
|
||||||
@@ -25,8 +26,14 @@ Input input_data(istream& in,bool prompt)
|
|||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
in >> in_data.numbers[i];
|
in >> in_data.numbers[i];
|
||||||
}
|
}
|
||||||
|
if (bins_cht == 0)
|
||||||
|
{
|
||||||
if (prompt)cerr << "Enter bin count: ";
|
if (prompt)cerr << "Enter bin count: ";
|
||||||
in >> in_data.bin_count;
|
in >> in_data.bin_count;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
in_data.bin_count = bins_cht;
|
||||||
|
|
||||||
return in_data;
|
return in_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +44,7 @@ static size_t write_data(void* items, size_t item_size, size_t item_count, void*
|
|||||||
buffer->write((char*)items, data_size);
|
buffer->write((char*)items, data_size);
|
||||||
return data_size;
|
return data_size;
|
||||||
}
|
}
|
||||||
Input download(const string& address)
|
Input download(const string& address, int bins_cht)
|
||||||
{
|
{
|
||||||
stringstream buffer;
|
stringstream buffer;
|
||||||
CURL* curl = curl_easy_init();
|
CURL* curl = curl_easy_init();
|
||||||
@@ -55,20 +62,56 @@ Input download(const string& address)
|
|||||||
}
|
}
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
return input_data(buffer, false);
|
return input_data(buffer, false, bins_cht);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsAllDigits(string s)
|
||||||
|
{
|
||||||
|
for(char c : s) if (!isdigit(c)) return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
setlocale(LC_ALL, "Russian");
|
||||||
Input input;
|
Input input;
|
||||||
if (argc > 1) {
|
bool get_bins = false;
|
||||||
input = download(argv[1]);
|
int get_bins_pos = -1;
|
||||||
|
int bins_cnt = 0;
|
||||||
|
string URL = "";
|
||||||
|
if (argc > 4)
|
||||||
|
{
|
||||||
|
cerr << "Количество параметров не должно превышать трех";
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
else {
|
if (argc > 1)
|
||||||
input = input_data(cin, true);
|
{
|
||||||
|
for (int i = 1; i < argc; i++)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[i], "-bins")==0)
|
||||||
|
{
|
||||||
|
get_bins = true;
|
||||||
|
get_bins_pos = i;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if ((IsAllDigits(argv[i])) && (get_bins_pos == (i-1)))
|
||||||
|
bins_cnt = atoi(argv[i]);
|
||||||
|
else
|
||||||
|
URL = argv[i];
|
||||||
|
}
|
||||||
|
if (get_bins && (bins_cnt == 0))
|
||||||
|
{
|
||||||
|
cerr << "После ключа -bins должно следовать натуральное число";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (URL == "")
|
||||||
|
input = input_data(cin, true, bins_cnt);
|
||||||
|
else
|
||||||
|
input = download(URL, bins_cnt);
|
||||||
|
|
||||||
auto bins = make_histogram(input.numbers, input.bin_count);
|
auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
show_histogram_svg(bins, input.numbers.size());
|
show_histogram_svg(bins, input.numbers.size());
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user