diff --git a/bin/Debug/devlab1.exe b/bin/Debug/devlab1.exe
deleted file mode 100644
index d1b77f8..0000000
Binary files a/bin/Debug/devlab1.exe and /dev/null differ
diff --git a/bin/Debug/unittest.exe b/bin/Debug/unittest.exe
new file mode 100644
index 0000000..9c487f1
Binary files /dev/null and b/bin/Debug/unittest.exe differ
diff --git a/devlab1.cbp b/devlab1.cbp
index 54beaa3..be13fc2 100644
--- a/devlab1.cbp
+++ b/devlab1.cbp
@@ -35,6 +35,7 @@
+
diff --git a/devlab1.depend b/devlab1.depend
index 3936491..4af22a7 100644
--- a/devlab1.depend
+++ b/devlab1.depend
@@ -1,14 +1,15 @@
# depslib dependency file v1.0
-1680528158 source:c:\program files\codeblocks\devlab1\main.cpp
+1681732107 source:c:\program files\codeblocks\devlab1\main.cpp
+
"histogram.h"
- "text.h"
+ "svg.h"
-1680530141 c:\program files\codeblocks\devlab1\histogram.h
+1681732312 c:\program files\codeblocks\devlab1\histogram.h
-1680530029 source:c:\program files\codeblocks\devlab1\histogram.cpp
+1681730387 source:c:\program files\codeblocks\devlab1\histogram.cpp
"histogram.h"
@@ -16,3 +17,14 @@
+1680530410 source:c:\program files\codeblocks\devlab1\text.cpp
+ "text.h"
+
+1681731817 c:\program files\codeblocks\devlab1\svg.h
+
+
+1681732105 source:c:\program files\codeblocks\devlab1\svg.cpp
+ "svg.h"
+
+
+
diff --git a/devlab1.layout b/devlab1.layout
index cecc2f7..2aea312 100644
--- a/devlab1.layout
+++ b/devlab1.layout
@@ -2,9 +2,19 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -12,19 +22,19 @@
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/doctest.h b/doctest.h
index 464beea..5c754cd 100644
--- a/doctest.h
+++ b/doctest.h
@@ -1,4 +1,3 @@
- // DOCTEST_H_INCLUDED
// ====================================================================== lgtm [cpp/missing-header-guard]
// == DO NOT MODIFY THIS FILE BY HAND - IT IS AUTO GENERATED BY CMAKE! ==
// ======================================================================
diff --git a/histogram.h b/histogram.h
index b158e7a..d06fd58 100644
--- a/histogram.h
+++ b/histogram.h
@@ -1,10 +1,9 @@
-#ifndef HISTOGRAM_H_INCLUDED
-#define HISTOGRAM_H_INCLUDED
+#pragma once
#include
-std::vector
+std::vector
make_histogram(const std::vector& numbers, size_t bin_count);
-
-
-#endif // HISTOGRAM_H_INCLUDED
+//void
+//show_histogram_text(std::vector bins, const std::vector& numbers, size_t bin_count);
+//
diff --git a/histogram_internal.h b/histogram_internal.h
index a31e616..19a82b9 100644
--- a/histogram_internal.h
+++ b/histogram_internal.h
@@ -1,6 +1,6 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
-
-find_minmax(const std::vector& numbers, double& min, double& max)
+void
+find_minmax(const std::vector& numbers, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
diff --git a/main.cpp b/main.cpp
index b27901f..14da376 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,14 +1,33 @@
#include
#include
+#include
#include "histogram.h"
-#include "text.h"
+#include "svg.h"
using namespace std;
+int inbl()
+{
+ int BLOCK_WIDTH;
+ cout << "block width is";
+ cin>>BLOCK_WIDTH;
+ if (BLOCK_WIDTH>30)
+ {
+ cout<< "too big, please make it smaller";
+ inbl;
+ }
+ else if (BLOCK_WIDTH<3)
+ {
+ cout<< "too small, please make it bigger";
+ inbl;
+ }
+ else return BLOCK_WIDTH;
+}
struct Input
{
vector numbers;
size_t bin_count;
+ int BLOCK_WIDTH;
};
Input
input_data()
@@ -23,6 +42,7 @@ input_data()
}
size_t bin_count;
cin >> bin_count;
+ int BLOCK_WIDTH = inbl();
return in;
}
@@ -31,7 +51,7 @@ int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
- show_histogram_text(bins);
+ show_histogram_svg(bins,in.BLOCK_WIDTH);
return 0;
diff --git a/marks.svg b/marks.svg
new file mode 100644
index 0000000..e69de29
diff --git a/marks.txt b/marks.txt
new file mode 100644
index 0000000..2cdb9aa
--- /dev/null
+++ b/marks.txt
@@ -0,0 +1,3 @@
+10
+3 3 4 4 4 4 4 5 5 5
+3
diff --git a/obj/Debug/main.o b/obj/Debug/main.o
index 94b16bc..7e92f87 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
new file mode 100644
index 0000000..ac15bc1
Binary files /dev/null and b/obj/Debug/svg.o differ
diff --git a/obj/Debug/unittest.o b/obj/Debug/unittest.o
new file mode 100644
index 0000000..f1f17ab
Binary files /dev/null and b/obj/Debug/unittest.o differ
diff --git a/svg.cpp b/svg.cpp
new file mode 100644
index 0000000..68ea97e
--- /dev/null
+++ b/svg.cpp
@@ -0,0 +1,80 @@
+#include "svg.h"
+#include
+#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(const 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/svg.h b/svg.h
new file mode 100644
index 0000000..aa7c3cc
--- /dev/null
+++ b/svg.h
@@ -0,0 +1,5 @@
+#pragma once
+#include
+
+void
+show_histogram_svg(const std::vector& bins, int BLOCK_WIDTH);
diff --git a/unittest.cbp b/unittest.cbp
index 6da4486..379d0a2 100644
--- a/unittest.cbp
+++ b/unittest.cbp
@@ -31,6 +31,10 @@
+
+
+
+
diff --git a/unittest.cpp b/unittest.cpp
index e69de29..981aa6f 100644
--- a/unittest.cpp
+++ b/unittest.cpp
@@ -0,0 +1,36 @@
+#define DOCTEST_CONFIG_NO_MULTITHREADING
+#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
+#include "doctest.h"
+#include "histogram_internal.h"
+
+TEST_CASE("distinct positive numbers") {
+ double min = 0;
+ double max = 0;
+ find_minmax({1, 2}, min, max);
+ CHECK(min == 1);
+ CHECK(max == 2);
+}
+
+TEST_CASE("distinct identical numbers") {
+ double min = 0;
+ double max = 0;
+ find_minmax({5, 5}, min, max);
+ CHECK(min == 5);
+ CHECK(max == 5);
+}
+
+TEST_CASE("distinct one number") {
+ double min = 0;
+ double max = 0;
+ find_minmax({3}, min, max);
+ CHECK(min == 3);
+ CHECK(max == 3);
+}
+
+TEST_CASE("distinct negative numbers") {
+ double min = 0;
+ double max = 0;
+ find_minmax({-3, -1}, min, max);
+ CHECK(min == -3);
+ CHECK(max == -1);
+}
diff --git a/unittest.depend b/unittest.depend
new file mode 100644
index 0000000..9a50203
--- /dev/null
+++ b/unittest.depend
@@ -0,0 +1,59 @@
+# depslib dependency file v1.0
+1680530029 source:c:\program files\codeblocks\devlab1\histogram.cpp
+ "histogram.h"
+
+
+1680530141 c:\program files\codeblocks\devlab1\histogram.h
+
+
+1681719645 source:c:\program files\codeblocks\devlab1\unittest.cpp
+ "doctest.h"
+ "histogram_internal.h"
+
+1681707623 c:\program files\codeblocks\devlab1\doctest.h
+
+
+
+
+
+
+ "doctest_fwd.h"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+