diff --git a/lab01.cbp b/lab01.cbp
index 833fc02..31a977b 100644
--- a/lab01.cbp
+++ b/lab01.cbp
@@ -13,7 +13,12 @@
+
+
+
+
+
diff --git a/main.cpp b/main.cpp
index c7ea2bd..485e357 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,6 +5,7 @@
#include "svg.h"
#include
#include
+#include
using namespace std;
@@ -16,50 +17,61 @@ struct Input {
};
Input
-input_data(istream& Newcin){
+input_data(istream& Newcin, bool prompt){
size_t number_count;
cerr << "Enter number count: ";
- Newcin >> number_count;
- bool prompt;
- cerr << "Do you want any prompts? Enter 'true' if yes, 'false' if no: ";
- Newcin >> prompt;
+ cin >> number_count;
if (prompt){
- cerr << "Prompt";
+ cerr << "Prompt" << endl;
}
-
Input in;
in.numbers.resize(number_count);
cerr << "Enter numbers: ";
for (size_t i = 0; i < number_count; i++) {
- Newcin >> in.numbers[i];
+ cin >> in.numbers[i];
}
cerr << "Enter bin count: ";
- Newcin >> in.bin_count;
+ cin >> in.bin_count;
cerr << "Enter stroke in format RGB: ";
- Newcin >> in.stroke;
+ cin >> in.stroke;
cerr << "Enter fill in format RGB: ";
- Newcin >> in.fill;
+ cin >> in.fill;
return in;
}
+Input
+download(const string& address) {
+ curl_global_init(CURL_GLOBAL_ALL);
+ stringstream buffer;
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ CURLcode res;
+ curl_easy_setopt(curl, CURLOPT_URL, address);
+ res = curl_easy_perform(curl);
+ if (res != 0){
+ cout << curl_easy_strerror(res);
+ 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) {
+
+ return 0;
+}
+
int
main(int argc, char* argv[]) {
+ Input input;
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);
- if (res != 0){
- cout << curl_easy_strerror(res);
- exit(1);
- }
- curl_easy_cleanup(curl);
- }
- return 0;
+ input = download(argv[1]);
+ } else {
+ input = input_data(cin, true);
}
- curl_global_init(CURL_GLOBAL_ALL);
- auto in = input_data(cin);
- auto bins = make_histogram(in.numbers, in.bin_count);
- show_histogram_svg(bins, in.stroke, in.fill);
+
+ const auto bins = make_histogram(input.numbers, input.bin_count);
+ show_histogram_svg(bins);
}
diff --git a/svg.cpp b/svg.cpp
index d19d479..de51dd1 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -26,7 +26,7 @@ svg_rect(double x, double y, double width, double height, string stroke, string
cout << "";
}
void
-show_histogram_svg(const vector& bins, string stroke, string fill) {
+show_histogram_svg(const vector& bins) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
@@ -48,7 +48,7 @@ show_histogram_svg(const vector& bins, string stroke, string fill) {
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
- svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
+ svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
svg_end();
@@ -58,7 +58,7 @@ show_histogram_svg(const vector& bins, string stroke, string fill) {
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin * kf;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
- svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
+ svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
svg_end();
diff --git a/svg.h b/svg.h
index a0911c2..1ca72d1 100644
--- a/svg.h
+++ b/svg.h
@@ -12,4 +12,4 @@ svg_text(double left, double baseline, std::string text);
void
svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black");
void
-show_histogram_svg(const std::vector& bins, std::string stroke, std::string fill);
+show_histogram_svg(const std::vector& bins);