diff --git a/bin/Debug/devlab1.exe b/bin/Debug/devlab1.exe
new file mode 100644
index 0000000..e8cbea5
Binary files /dev/null and b/bin/Debug/devlab1.exe differ
diff --git a/bin/Debug/input.txt b/bin/Debug/input.txt
index 9bbd76e..9e79f5d 100644
--- a/bin/Debug/input.txt
+++ b/bin/Debug/input.txt
@@ -1,3 +1,4 @@
10
3 3 3 4 4 4 4 4 5 5
-3
\ No newline at end of file
+3
+12
\ No newline at end of file
diff --git a/bin/Debug/mark.svg b/bin/Debug/mark.svg
new file mode 100644
index 0000000..3f03883
--- /dev/null
+++ b/bin/Debug/mark.svg
@@ -0,0 +1,6 @@
+
+
diff --git a/devlab1.depend b/devlab1.depend
index 3ed20c5..f77c49c 100644
--- a/devlab1.depend
+++ b/devlab1.depend
@@ -1,17 +1,18 @@
# depslib dependency file v1.0
-1681732107 source:c:\program files\codeblocks\devlab1\main.cpp
+1681739567 source:c:\program files\codeblocks\devlab1\main.cpp
"histogram.h"
"svg.h"
-1681733106 c:\program files\codeblocks\devlab1\histogram.h
+1681733870 c:\program files\codeblocks\devlab1\histogram.h
-1681730387 source:c:\program files\codeblocks\devlab1\histogram.cpp
+1681738471 source:c:\program files\codeblocks\devlab1\histogram.cpp
"histogram.h"
+
1680530385 c:\program files\codeblocks\devlab1\text.h
@@ -20,10 +21,10 @@
1680530410 source:c:\program files\codeblocks\devlab1\text.cpp
"text.h"
-1681733452 c:\program files\codeblocks\devlab1\svg.h
+1681734640 c:\program files\codeblocks\devlab1\svg.h
-1681733443 source:c:\program files\codeblocks\devlab1\svg.cpp
+1681739461 source:c:\program files\codeblocks\devlab1\svg.cpp
"svg.h"
diff --git a/histogram.cpp b/histogram.cpp
index bd4803e..17c02b2 100644
--- a/histogram.cpp
+++ b/histogram.cpp
@@ -1,5 +1,6 @@
#include "histogram.h"
#include
+#include
using namespace std;
void
find_minmax(const vector& numbers, double& min, double& max)
@@ -14,17 +15,18 @@ find_minmax(const vector& numbers, double& min, double& max)
};
std::vector
-make_histogram(const vector& numbers,size_t bin_count)
+make_histogram(const vector &numbers,size_t bin_count)
{
float lo,hi,dif;
double min, max;
find_minmax(numbers, min, max);
+ //std::cout< bins(bin_count) ;
dif=(max - min)/bin_count;
for(int i=0; i < numbers.size(); i++)
{
bool found = false;
- for (int j=0; (j < bin_count-1)&&!found; j++)
+ for (size_t j=0; (j < bin_count-1)&&(!found); j++)
{
lo= min + j*dif;
hi= min + (j+1)*dif;
@@ -33,11 +35,19 @@ make_histogram(const vector& numbers,size_t bin_count)
bins[j]++;
found = true;
}
+ // std::cout<
make_histogram(const std::vector& numbers, size_t bin_count);
-//void
-//show_histogram_text(std::vector bins, const std::vector& numbers, size_t bin_count);
-//
+void
+show_histogram_text(std::vector bins, const std::vector& numbers, size_t bin_count);
diff --git a/main.cpp b/main.cpp
index 4a312d9..d0acf30 100644
--- a/main.cpp
+++ b/main.cpp
@@ -8,16 +8,16 @@ using namespace std;
int inbl()
{
int BLOCK_WIDTH;
- cout << "block width is";
+ cerr << "block width is";
cin>>BLOCK_WIDTH;
if (BLOCK_WIDTH>30)
{
- cout<< "too big, please make it smaller";
+ cerr<< "too big, please make it smaller";
inbl;
}
else if (BLOCK_WIDTH<3)
{
- cout<< "too small, please make it bigger";
+ cerr<< "too small, please make it bigger";
inbl;
}
else return BLOCK_WIDTH;
@@ -26,32 +26,43 @@ int inbl()
struct Input
{
vector numbers;
- size_t bin_count;
+ int bin_count;
int BLOCK_WIDTH;
};
Input
input_data()
{
- size_t number_count;
+ size_t number_count=0;
+ cerr<<"amount of numbers is";
cin >> number_count;
- Input in;
+Input in;
in.numbers.resize(number_count);
+ cerr<<"let's intro numbers ";
for (size_t i = 0; i < number_count; i++)
{
cin >> in.numbers[i];
}
- size_t bin_count;
- cin >> bin_count;
+ size_t bin_count=0;
+ cerr<<"amount of bins is";
+ cin >> in.bin_count;
int BLOCK_WIDTH = inbl();
return in;
}
-
+//4199705
+//0x71fdf8
+//4199705
int main()
{
auto in = input_data();
+
+
+
+ //std::cout<
+#include
+
+using namespace std;
+
+void
+svg_begin(double width, double height)
+{
+ cout << "\n";
+ cout << "\n";
+}
+
+void
+svg_text(double left, double baseline, string text)
+{
+ cout << "" << text << "";
+}
+
+void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black")
+{
+ cout << "";
+}
+
+void
+show_histogram_svg(vector & bins, int BLOCK_WIDTH)
+{
+
+ const auto IMAGE_WIDTH = 400;
+ const auto IMAGE_HEIGHT = 300;
+ const auto TEXT_LEFT = 20;
+ const auto TEXT_BASELINE = 20;
+ const auto TEXT_WIDTH = 50;
+ const auto BIN_HEIGHT = 30;
+
+
+
+ svg_begin(400, 300);
+
+ double top = 0;
+ const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
+ auto maxb = bins[0];
+
+ for (size_t j = 1; j < bins.size(); j++)
+ {
+ if (bins[j] > maxb) maxb = bins[j];
+ }
+
+ auto maxb1 = maxb * BLOCK_WIDTH;
+
+ for (size_t bin : bins)
+ {
+
+ double bin_width;
+
+ int color = (10 - (bin * 9) / maxb);
+
+ if (maxb1 > MAX_ASTERISK)
+ {
+ bin_width = BLOCK_WIDTH * MAX_ASTERISK * (bin / maxb1);
+ }
+ else bin_width = BLOCK_WIDTH * bin;
+
+ svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
+ svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "violet", to_string(color));
+ top += BIN_HEIGHT;
+ }
+
+ svg_end();
+}
diff --git a/obj/Debug/histogram.o b/obj/Debug/histogram.o
index 12f41f8..6724c9e 100644
Binary files a/obj/Debug/histogram.o and b/obj/Debug/histogram.o differ
diff --git a/obj/Debug/main.o b/obj/Debug/main.o
index c93adec..3e14e73 100644
Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ
diff --git a/obj/Debug/svg.o b/obj/Debug/svg.o
index 6b528f7..f88a306 100644
Binary files a/obj/Debug/svg.o and b/obj/Debug/svg.o differ
diff --git a/svg.cpp b/svg.cpp
index 640cf36..5d4f64b 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -29,11 +29,11 @@ svg_text(double left, double baseline, string text)
void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black")
{
- cout << "";
+ cout << ""<& bins, int BLOCK_WIDTH)
+show_histogram_svg(vector & bins, int BLOCK_WIDTH)
{
const auto IMAGE_WIDTH = 400;
@@ -44,7 +44,7 @@ show_histogram_svg( vector& bins, int BLOCK_WIDTH)
const auto BIN_HEIGHT = 30;
-
+BLOCK_WIDTH=BLOCK_WIDTH+12;
svg_begin(400, 300);
double top = 0;
@@ -58,12 +58,14 @@ show_histogram_svg( vector& bins, int BLOCK_WIDTH)
auto maxb1 = maxb * BLOCK_WIDTH;
+ int i = 0;
+
for (size_t bin : bins)
{
double bin_width;
- int color = (10 - (bin * 9) / maxb);
+ int color = 10;
if (maxb1 > MAX_ASTERISK)
{
@@ -74,7 +76,12 @@ show_histogram_svg( vector& bins, int BLOCK_WIDTH)
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "violet", to_string(color));
top += BIN_HEIGHT;
+ if (i == 4)
+ break;
+ else
+ i++;
}
svg_end();
}
+