diff --git a/bin/Debug/devlab1.exe b/bin/Debug/devlab1.exe
index eb53047..560ff8e 100644
Binary files a/bin/Debug/devlab1.exe and b/bin/Debug/devlab1.exe differ
diff --git a/bin/Debug/input.txt b/bin/Debug/input.txt
index 8739895..36a8939 100644
--- a/bin/Debug/input.txt
+++ b/bin/Debug/input.txt
@@ -1,4 +1,3 @@
10
3 3 3 4 4 4 4 4 5 5
3
-16
\ No newline at end of file
diff --git a/bin/Debug/libcurl-x64.dll b/bin/Debug/libcurl-x64.dll
new file mode 100644
index 0000000..407419e
Binary files /dev/null and b/bin/Debug/libcurl-x64.dll differ
diff --git a/bin/Debug/libcurl.dll b/bin/Debug/libcurl.dll
deleted file mode 100644
index 7b5f79a..0000000
Binary files a/bin/Debug/libcurl.dll and /dev/null differ
diff --git a/bin/Debug/libcurl.dll.a b/bin/Debug/libcurl.dll.a
new file mode 100644
index 0000000..b989c52
Binary files /dev/null and b/bin/Debug/libcurl.dll.a differ
diff --git a/bin/Debug/marks.svg b/bin/Debug/marks.svg
new file mode 100644
index 0000000..e69de29
diff --git a/devlab1.cbp b/devlab1.cbp
index 7b50db8..8cec0ed 100644
--- a/devlab1.cbp
+++ b/devlab1.cbp
@@ -13,7 +13,13 @@
+
+
+
+
+
+
@@ -37,7 +43,6 @@
-
diff --git a/devlab1.depend b/devlab1.depend
index 1711783..0a6132b 100644
--- a/devlab1.depend
+++ b/devlab1.depend
@@ -1,15 +1,19 @@
# depslib dependency file v1.0
-1685054501 source:c:\program files\codeblocks\devlab1\main.cpp
-
-
-
+1685368116 source:c:\program files\codeblocks\devlab1\main.cpp
+
+
+
+ "text.h"
"histogram.h"
"svg.h"
+ "histogram_internal.h"
+
+
1681733870 c:\program files\codeblocks\devlab1\histogram.h
-1685054519 source:c:\program files\codeblocks\devlab1\histogram.cpp
+1685554919 source:c:\program files\codeblocks\devlab1\histogram.cpp
"histogram.h"
@@ -24,8 +28,106 @@
1682337558 c:\program files\codeblocks\devlab1\svg.h
-1685054342 source:c:\program files\codeblocks\devlab1\svg.cpp
+1685369210 source:c:\program files\codeblocks\devlab1\svg.cpp
"svg.h"
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\curl.h
+ "curlver.h"
+ "system.h"
+
+
+
+
+
+
+
+
+
+
+ "easy.h"
+ "multi.h"
+ "urlapi.h"
+ "options.h"
+ "header.h"
+ "websockets.h"
+ "typecheck-gcc.h"
+
+1684811606 c:\program files\codeblocks\devlab1\curl\include\curl\curlver.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\system.h
+
+
+
+
+
+
+
+
+1684736752 c:\program files\codeblocks\devlab1\curl\include\curl\easy.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\multi.h
+ "curl.h"
+
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\urlapi.h
+ "curl.h"
+
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\options.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\header.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\websockets.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\include\curl\typecheck-gcc.h
+
+1685551862 c:\program files\codeblocks\devlab1\histogram_internal.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\curl.h
+ "curlver.h"
+ "system.h"
+
+
+
+
+
+
+
+
+
+
+ "easy.h"
+ "multi.h"
+ "urlapi.h"
+ "options.h"
+ "header.h"
+ "websockets.h"
+ "typecheck-gcc.h"
+
+1684811606 c:\program files\codeblocks\devlab1\curl\curl\include\curl\curlver.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\system.h
+
+
+
+
+
+
+
+
+1684736752 c:\program files\codeblocks\devlab1\curl\curl\include\curl\easy.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\multi.h
+ "curl.h"
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\urlapi.h
+ "curl.h"
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\options.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\header.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\websockets.h
+
+1684137360 c:\program files\codeblocks\devlab1\curl\curl\include\curl\typecheck-gcc.h
+
diff --git a/devlab1.layout b/devlab1.layout
index 285cb9a..edd21b7 100644
--- a/devlab1.layout
+++ b/devlab1.layout
@@ -2,14 +2,14 @@
-
+
-
+
-
+
-
+
@@ -17,14 +17,14 @@
-
+
-
+
-
+
-
+
@@ -32,14 +32,14 @@
-
+
-
+
-
+
-
+
diff --git a/histogram.cpp b/histogram.cpp
index 054221b..f803ea4 100644
--- a/histogram.cpp
+++ b/histogram.cpp
@@ -3,17 +3,22 @@
#include
using namespace std;
bool
-find_minmax(const vector& numbers, double& min, double& max)
+find_minmax(const vector& numbers, double& min1, double& max1)
{
+ for (size_t i = 0; i < numbers.size(); i++)
+
+ {
+ cerr< max) max=numbers[i];
- if (numbers[i] < min) min=numbers[i];
+ if (numbers[i] > max1) max1=numbers[i];
+ if (numbers[i] < min1) min1=numbers[i];
}
return true;
@@ -22,27 +27,23 @@ std::vector
make_histogram(const vector &numbers,size_t bin_count)
{
float lo,hi,dif;
- double min, max;
+ double min1, max1;
+ find_minmax(numbers,min1, max1);
// if(!find_minmax(numbers, min, max))
// return 1;
- vector bins(bin_count) ;
- dif=(max - min)/bin_count;
- for(int i=0; i < numbers.size(); i++)
- {
- bool found = false;
- for (size_t j=0; (j < bin_count-1)&&(!found); j++)
- {
- lo= min + j*dif;
- hi= min + (j+1)*dif;
- if ((lo <= numbers[i]) && (numbers[i] bins(bin_count);
+ dif=(max1 - min1)/bin_count;
+for (size_t i = 0; i < numbers.size(); i++) {
+ bool found = false;
+ for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
+ auto lo = min1 + j * dif;
+ auto hi = min1 + (j + 1) * dif;
+ if ((lo <= numbers[i]) && (numbers[i] < hi)) {
+ bins[j]++;
+ found = true;
}
- if (!found)
+ }
+ if (found == false)
{
bins[bin_count - 1]++;
}
diff --git a/histogram_internal.h b/histogram_internal.h
index 75671e7..4ac4c6a 100644
--- a/histogram_internal.h
+++ b/histogram_internal.h
@@ -1,6 +1,6 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
bool
-find_minmax(const std::vector& numbers, double& min, double& max);
+find_minmax(const std::vector& numbers, double& min1, double& max1);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
diff --git a/main.cpp b/main.cpp
index e780892..19e2fc3 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,9 +1,12 @@
-#include
-#include
-#include
+#include
+#include
+#include
+#include "text.h"
#include "histogram.h"
#include "svg.h"
-#include
+#include "histogram_internal.h"
+#include
+#include
using namespace std;
@@ -12,45 +15,86 @@ struct Input
vector numbers;
int bin_count;
};
+size_t
+write_data(void* items, size_t item_size, size_t item_count, void* ctx)
+{
+ size_t data_size = item_size * item_count;
+
+ stringstream* buffer = reinterpret_cast(ctx);
+ buffer->write(reinterpret_cast(items), data_size);
+
+ return data_size;
+}
+
Input
-input_data(istream& in, bool prompt){
+input_data(istream& in, bool prompt)
+{
size_t number_count;
in >> number_count;
Input inp;
inp.numbers.resize(number_count);
- if (prompt){
+ if (prompt)
+ {
std::cerr << "enter bin_count";
}
-
- for (size_t i = 0; i < number_count; i++){
+ inp.numbers.resize(number_count);
+ for (size_t i = 0; i < number_count; i++)
+ {
in >> inp.numbers[i];
+
}
in >> inp.bin_count;
return inp;
}
+Input
+download(const string& address)
+{
+ stringstream buffer;
+
+ CURL* curl = curl_easy_init();
+ if (curl)
+ {
+ CURLcode res;
+ 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) &&
+ !curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip) && ip) {
+ cerr<<("IP: %s\n", ip);
+ }
+
+ if (res != 0)
+ {
+ cout << curl_easy_strerror(res);
+ exit(1);
+ }
+ }
+
+ curl_easy_cleanup(curl);
+ return input_data(buffer, false);
+}
+
int
main(int argc, char* argv[])
{
- if (argc > 1){
- cerr << "argv[0] = " << argv[0] << "argc = " << argc;
-
- CURL *curl = curl_easy_init();
-if(curl) {
- CURLcode res;
- curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
- res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
+ Input in;
+ if (argc > 1)
+ {
+ in = download(argv[1]);
}
- return 0;}
+ else
+ {
+ in = input_data(cin, true);
+ }
+
- curl_global_init(CURL_GLOBAL_ALL);
- auto in = input_data(cin, true);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
diff --git a/svg.cpp b/svg.cpp
index 117c788..4fff31f 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -78,8 +78,8 @@ show_histogram_svg(vector & bins)
}
else
bin_width = BLOCK_WIDTH * bin;
-
- cerr << "\n" << bin_width << "\n";
+//cerr << "\n" << bin << "\n";
+ // cerr << "\n" << bin_width << "\n";
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));