diff --git a/cs-lab34.exe b/cs-lab34.exe
new file mode 100644
index 0000000..e69de29
diff --git a/hehehe.cbp b/hehehe.cbp
index 91da4b9..43bc407 100644
--- a/hehehe.cbp
+++ b/hehehe.cbp
@@ -32,7 +32,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/hehehe.depend b/hehehe.depend
new file mode 100644
index 0000000..3e23f3a
--- /dev/null
+++ b/hehehe.depend
@@ -0,0 +1,82 @@
+# depslib dependency file v1.0
+1713791550 source:c:\users\u113-02\desktop\hehehe\main.cpp
+
+
+
+
+1714330914 source:e:\hehehe\main.cpp
+
+
+
+
+1714921863 source:c:\users\nick\desktop\hehehe\main.cpp
+
+
+
+ "histogram.h"
+ "svg.h"
+ "text.h"
+
+1714861965 c:\users\nick\desktop\hehehe\histogram.h
+
+
+1714862011 source:c:\users\nick\desktop\hehehe\histogram.cpp
+ "histogram.h"
+
+
+
+1714919929 source:c:\users\nick\desktop\hehehe\svg.cpp
+
+
+
+ "svg.h"
+
+1714919958 c:\users\nick\desktop\hehehe\svg.h
+
+
+
+1714921819 c:\users\nick\desktop\hehehe\text.h
+
+
+1714921889 source:c:\users\nick\desktop\hehehe\text.cpp
+ "text.h"
+ "svg.h"
+
+
+
+1714862012 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.cpp
+ "histogram.h"
+
+
+
+1714861966 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.h
+
+
+1714997928 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\main.cpp
+
+
+
+ "histogram.h"
+ "svg.h"
+ "text.h"
+
+1714997791 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\svg.h
+
+
+
+1714996911 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\text.h
+
+
+1714997791 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\text.cpp
+ "text.h"
+ "svg.h"
+
+
+ "text.h"
+
+1714997285 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\svg.cpp
+
+
+
+ "svg.h"
+
diff --git a/hehehe.layout b/hehehe.layout
new file mode 100644
index 0000000..b0b1d0a
--- /dev/null
+++ b/hehehe.layout
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/histogram.cpp b/histogram.cpp
new file mode 100644
index 0000000..4c759c6
--- /dev/null
+++ b/histogram.cpp
@@ -0,0 +1,43 @@
+#include "histogram.h"
+#include
+#include
+using namespace std;
+
+void
+find_minmax(const vector& numbers, double& min, double& max) {
+ min = numbers[0];
+ max = numbers[0];
+ for (double x : numbers) {
+ if (x < min) {
+ min = x;
+ }
+ else if (x > max) {
+ max = x;
+ }
+ }
+}
+
+std::vector
+make_histogram(const std::vector& numbers, size_t bin_count) {
+ vector bins(bin_count);
+
+ double min = 0, max = 0;
+ find_minmax(numbers, min, max);
+
+ double bin_size = (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++) {
+ auto lo = min + j * bin_size;
+ auto hi = min + (j + 1) * bin_size;
+ if ((lo <= numbers[i]) && (numbers[i] < hi)) {
+ bins[j]++;
+ found = true;
+ }
+ }
+ if (!found) {
+ bins[bin_count - 1]++;
+ }
+ }
+ return bins;
+}
diff --git a/histogram.h b/histogram.h
new file mode 100644
index 0000000..2044428
--- /dev/null
+++ b/histogram.h
@@ -0,0 +1,5 @@
+#pragma once
+#include
+
+std::vector
+make_histogram(const std::vector& numbers, size_t bin_count);
diff --git a/histogram_internal.h b/histogram_internal.h
new file mode 100644
index 0000000..b9b8634
--- /dev/null
+++ b/histogram_internal.h
@@ -0,0 +1,4 @@
+#pragma once
+#include
+void
+find_minmax(const std::vector& numbers, double& min, double& max);
diff --git a/main.cpp b/main.cpp
index 716c943..7a12515 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,7 +2,8 @@
#include
#include
#include "histogram.h"
-
+#include "svg.h"
+#include "text.h"
using namespace std;
@@ -31,8 +32,9 @@ cin >> in.bin_count;
while (true) {
- cerr << "Screen width: ";
- cin >> in.SCREEN_WIDTH;
+ //cerr << "Screen width: ";
+ //cin >> in.SCREEN_WIDTH;
+ in.SCREEN_WIDTH=80;
if (in.SCREEN_WIDTH < 7) {
cerr << "<7"; cerr << endl;
continue;
@@ -55,41 +57,7 @@ cin >> in.bin_count;
-void show_histogram_text (const std::vector& bins, size_t MAX_ASTERISK, size_t bin_count)
-{
- double mxbins = bins[0];
-
- for (double x : bins)
- {
- if (x > mxbins)
- mxbins = x;
- }
- double k;
-
- if (mxbins > MAX_ASTERISK)
- k = MAX_ASTERISK / mxbins;
- else
- k = 1;
- for (size_t i = 0; i < bin_count; i++)
- {
- if (bins[i] < 10) {
- cout << " " << bins[i] << "|";
- }
- else if (bins[i] < 100) {
- cout << " " << bins[i] << "|";
- }
- else if (bins[i] < 1000) {
- cout << bins[i] << "|";
- }
- for (int j = 0; j < floor(bins[i] * k); j++)
- {
- cout << "*";
- }
-
- cout << endl;
- }
-}
int main()
{
@@ -107,8 +75,9 @@ int main()
auto bins = make_histogram(in.numbers, in.bin_count);
-show_histogram_text(bins, MAX_ASTERISK, in.bin_count);
+//show_histogram_text(bins, MAX_ASTERISK, in.bin_count);
+show_histogram_svg(bins);
}
diff --git a/svg.cpp b/svg.cpp
new file mode 100644
index 0000000..4b5da22
--- /dev/null
+++ b/svg.cpp
@@ -0,0 +1,59 @@
+#include
+#include
+#include
+#include "svg.h"
+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, string fill) {
+ cout << "";
+}
+
+void
+show_histogram_svg(const std::vector& bins) {
+
+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;
+const auto BLOCK_WIDTH = 10;
+const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
+
+double max_count = (bins[0] * BLOCK_WIDTH);
+ for (double bin : bins) {
+ if ((bin * BLOCK_WIDTH) > max_count) {
+ max_count = (bin * BLOCK_WIDTH);
+ }
+ }
+
+ svg_begin(400, 300);
+ double top = 0;
+ 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, "red", "#00ffff");
+ top += 2*BIN_HEIGHT;
+}
+}
diff --git a/svg.h b/svg.h
new file mode 100644
index 0000000..4d012fb
--- /dev/null
+++ b/svg.h
@@ -0,0 +1,5 @@
+#pragma once
+#include
+#include
+void show_histogram_svg(const std::vector& bins);
+
diff --git a/text.cpp b/text.cpp
new file mode 100644
index 0000000..9708931
--- /dev/null
+++ b/text.cpp
@@ -0,0 +1,42 @@
+#include "text.h"
+#include "svg.h"
+#include
+#include
+#include "text.h"
+using namespace std;
+
+void show_histogram_text (const std::vector& bins, size_t MAX_ASTERISK, size_t bin_count)
+{
+ double mxbins = bins[0];
+
+ for (double x : bins)
+ {
+ if (x > mxbins)
+ mxbins = x;
+ }
+ double k;
+
+ if (mxbins > MAX_ASTERISK)
+ k = MAX_ASTERISK / mxbins;
+ else
+ k = 1;
+ for (size_t i = 0; i < bin_count; i++)
+ {
+ if (bins[i] < 10) {
+ cout << " " << bins[i] << "|";
+ }
+ else if (bins[i] < 100) {
+ cout << " " << bins[i] << "|";
+ }
+ else if (bins[i] < 1000) {
+ cout << bins[i] << "|";
+
+ }
+ for (int j = 0; j < int(bins[i] * k); j++)
+ {
+ cout << "*";
+ }
+
+ cout << endl;
+ }
+}
diff --git a/text.h b/text.h
new file mode 100644
index 0000000..12f91da
--- /dev/null
+++ b/text.h
@@ -0,0 +1,5 @@
+#pragma once
+#include
+
+void show_histogram_text(const std::vector& bins, size_t MAX_ASTERISK, size_t bin_count);
+
diff --git a/unittest.cbp b/unittest.cbp
new file mode 100644
index 0000000..534f497
--- /dev/null
+++ b/unittest.cbp
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/unittest.cpp b/unittest.cpp
new file mode 100644
index 0000000..a9ba7e5
--- /dev/null
+++ b/unittest.cpp
@@ -0,0 +1,12 @@
+#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);
+}
diff --git a/unittest.depend b/unittest.depend
new file mode 100644
index 0000000..3f7180c
--- /dev/null
+++ b/unittest.depend
@@ -0,0 +1,121 @@
+# depslib dependency file v1.0
+1714862011 source:c:\users\nick\desktop\hehehe\histogram.cpp
+ "histogram.h"
+
+
+
+1714861965 c:\users\nick\desktop\hehehe\histogram.h
+
+
+1714917108 source:c:\users\nick\desktop\hehehe\unittest.cpp
+ "doctest.h"
+ "histogram_internal.h"
+
+1714916946 c:\users\nick\desktop\hehehe\doctest.h
+
+
+
+
+
+
+ "doctest_fwd.h"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+