diff --git a/bin/Debug/01-example.actual.txt b/bin/Debug/01-example.actual.txt
new file mode 100644
index 0000000..b0a2599
--- /dev/null
+++ b/bin/Debug/01-example.actual.txt
@@ -0,0 +1,3 @@
+ 2|**
+ 5|*****
+ 3|***
diff --git a/bin/Debug/01-example.expected.txt b/bin/Debug/01-example.expected.txt
new file mode 100644
index 0000000..b0a2599
--- /dev/null
+++ b/bin/Debug/01-example.expected.txt
@@ -0,0 +1,3 @@
+ 2|**
+ 5|*****
+ 3|***
diff --git a/bin/Debug/01-example.input.txt b/bin/Debug/01-example.input.txt
new file mode 100644
index 0000000..6ef9fde
--- /dev/null
+++ b/bin/Debug/01-example.input.txt
@@ -0,0 +1,3 @@
+10
+4 4 3 5 3 4 5 5 4 4
+3
diff --git a/bin/Debug/02-alignment.expected.txt b/bin/Debug/02-alignment.expected.txt
new file mode 100644
index 0000000..094c19f
--- /dev/null
+++ b/bin/Debug/02-alignment.expected.txt
@@ -0,0 +1,3 @@
+ 9|*********
+ 33|*********************************
+100|****************************************************************************************************
diff --git a/bin/Debug/02-alignment.input.txt b/bin/Debug/02-alignment.input.txt
new file mode 100644
index 0000000..2539400
--- /dev/null
+++ b/bin/Debug/02-alignment.input.txt
@@ -0,0 +1,5 @@
+142
+1 1 1 1 1 1 1 1 1
+2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
+3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
+3
diff --git a/bin/Debug/lab01.exe b/bin/Debug/lab01.exe
new file mode 100644
index 0000000..eeaf532
Binary files /dev/null and b/bin/Debug/lab01.exe differ
diff --git a/bin/Debug/marks.svg b/bin/Debug/marks.svg
new file mode 100644
index 0000000..4182ab9
--- /dev/null
+++ b/bin/Debug/marks.svg
@@ -0,0 +1,3 @@
+
+
diff --git a/bin/Debug/marks.txt b/bin/Debug/marks.txt
new file mode 100644
index 0000000..2cdb9aa
--- /dev/null
+++ b/bin/Debug/marks.txt
@@ -0,0 +1,3 @@
+10
+3 3 4 4 4 4 4 5 5 5
+3
diff --git a/bin/Debug/test1.bat b/bin/Debug/test1.bat
new file mode 100644
index 0000000..bfa37f2
--- /dev/null
+++ b/bin/Debug/test1.bat
@@ -0,0 +1,2 @@
+lab01.exe < 01-example.input.txt > 01-example.actual.txt 2>NUL
+fc /N 01-example.actual.txt 01-example.expected.txt || pause
\ No newline at end of file
diff --git a/bin/Debug/test2.bat b/bin/Debug/test2.bat
new file mode 100644
index 0000000..224c184
--- /dev/null
+++ b/bin/Debug/test2.bat
@@ -0,0 +1,2 @@
+lab01.exe < 02-alignment.input.txt > 01-example.actual.txt 2>NUL
+fc /N 01-example.actual.txt 02-alignment.expected.txt || pause
\ No newline at end of file
diff --git a/bin/Debug/unittest.exe b/bin/Debug/unittest.exe
new file mode 100644
index 0000000..0343f43
Binary files /dev/null and b/bin/Debug/unittest.exe differ
diff --git a/histogram.cpp b/histogram.cpp
new file mode 100644
index 0000000..932942b
--- /dev/null
+++ b/histogram.cpp
@@ -0,0 +1,58 @@
+#include "histogram.h"
+#include "histogram_internal.h"
+
+using namespace std;
+
+void
+find_minmax(const vector& numbers, double& min, double& max)
+{
+ min = numbers[0];
+ max = numbers[0];
+ for (double x : numbers)
+ {
+ if (xmax)
+ {
+ max=x;
+ }
+ }
+}
+
+vector
+make_histogram(const vector& numbers, size_t bin_count)
+{
+ vector bins(bin_count);
+ double min, max;
+ find_minmax(numbers, min, max);
+
+ double bin_size = (max - min) / bin_count;
+
+ size_t max_count = 0;
+
+ 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 = min + j * bin_size;
+ auto hi = min + (j + 1) * bin_size;
+ if ((lo <= numbers[i]) && (numbers[i] < hi))
+ {
+ bins[j]++;
+ if (bins[j] > max_count)
+ {
+ max_count = 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..0d8dc8c
--- /dev/null
+++ b/histogram.h
@@ -0,0 +1,9 @@
+#ifndef HISTOGRAM_H_INCLUDED
+#define HISTOGRAM_H_INCLUDED
+
+#include
+
+std::vector
+make_histogram(const std::vector& numbers, size_t bin_count);
+
+#endif // HISTOGRAM_H_INCLUDED
diff --git a/histogram_internal.h b/histogram_internal.h
new file mode 100644
index 0000000..3a2e060
--- /dev/null
+++ b/histogram_internal.h
@@ -0,0 +1,9 @@
+#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
+#define HISTOGRAM_INTERNAL_H_INCLUDED
+
+#include
+
+void
+find_minmax(const std::vector& numbers, double& min, double& max);
+
+#endif // HISTOGRAM_INTERNAL_H_INCLUDED
diff --git a/lab01 b/lab01
new file mode 100644
index 0000000..e69de29
diff --git a/lab01.cbp b/lab01.cbp
index e4dd928..61d707f 100644
--- a/lab01.cbp
+++ b/lab01.cbp
@@ -40,6 +40,10 @@
+
+
+
+
diff --git a/lab01.depend b/lab01.depend
new file mode 100644
index 0000000..96e2d3c
--- /dev/null
+++ b/lab01.depend
@@ -0,0 +1,29 @@
+# depslib dependency file v1.0
+1746385589 source:c:\users\krivo\desktop\lab03\main.cpp
+
+
+ "histogram.h"
+ "text.h"
+ "svg.h"
+
+1746381170 c:\users\krivo\desktop\lab03\histogram.h
+
+
+1746383913 source:c:\users\krivo\desktop\lab03\histogram.cpp
+ "histogram.h"
+ "histogram_internal.h"
+
+1746381509 c:\users\krivo\desktop\lab03\text.h
+
+
+1746382043 source:c:\users\krivo\desktop\lab03\text.cpp
+ "text.h"
+
+
+1746383746 c:\users\krivo\desktop\lab03\histogram_internal.h
+
+
+1746386429 c:\users\krivo\desktop\lab03\svg.h
+
+
+
diff --git a/lab01.layout b/lab01.layout
new file mode 100644
index 0000000..e53d0ab
--- /dev/null
+++ b/lab01.layout
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main.cpp b/main.cpp
index 1c3d92b..0765ef7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,6 +2,7 @@
#include
#include "histogram.h"
#include "text.h"
+#include "svg.h"
using namespace std;
@@ -19,8 +20,6 @@ input_data ()
{
Input in;
- cin >> in.bin_count;
-
size_t number_count;
cerr << "enter number count: ";
cin >> number_count;
@@ -31,6 +30,7 @@ input_data ()
cerr << "enter number" << (i+1) << ": ";
cin >> in.numbers[i];
}
+ cin >> in.bin_count;
return in;
}
@@ -39,5 +39,5 @@ main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
- show_histogram_text(bins, in.bin_count);
+ show_histogram_svg(bins);
}
diff --git a/main.exe b/main.exe
new file mode 100644
index 0000000..99f86cc
Binary files /dev/null and b/main.exe differ
diff --git a/main.o b/main.o
new file mode 100644
index 0000000..625d620
Binary files /dev/null and b/main.o differ
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/histogram.o b/obj/Debug/histogram.o
new file mode 100644
index 0000000..55243d7
Binary files /dev/null and b/obj/Debug/histogram.o differ
diff --git a/obj/Debug/main.o b/obj/Debug/main.o
new file mode 100644
index 0000000..49d5981
Binary files /dev/null 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..06e12a5
Binary files /dev/null and b/obj/Debug/svg.o differ
diff --git a/obj/Debug/text.o b/obj/Debug/text.o
new file mode 100644
index 0000000..f47d659
Binary files /dev/null and b/obj/Debug/text.o differ
diff --git a/obj/Debug/unittest.o b/obj/Debug/unittest.o
new file mode 100644
index 0000000..8de6f0e
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..3b1d9d7
--- /dev/null
+++ b/svg.cpp
@@ -0,0 +1,67 @@
+#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, string fill)
+{
+ cout << "";
+}
+
+void
+show_histogram_svg(const 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;
+
+ svg_begin(400, 300);
+ double top = 0;
+
+ for (size_t bin : bins)
+ {
+ const double bin_width = BLOCK_WIDTH * bin;
+ if(bin_width> IMAGE_WIDTH)
+ {
+ const double bin_width= IMAGE_WIDTH - TEXT_WIDTH;
+ }
+ svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
+ svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "light blue");
+ top += BIN_HEIGHT;
+ }
+
+ //svg_text(20, 20, to_string(bins[0]));
+ //svg_rect(50, 0, bins[0] * 10, 30);
+ svg_end();
+}
+
diff --git a/svg.h b/svg.h
new file mode 100644
index 0000000..4cb0f0e
--- /dev/null
+++ b/svg.h
@@ -0,0 +1,23 @@
+#ifndef SVG_H_INCLUDED
+#define SVG_H_INCLUDED
+#include
+#include
+
+using namespace std;
+
+void
+svg_begin(double width, double height);
+
+void
+svg_end();
+
+void
+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");
+
+void
+show_histogram_svg(const vector& bins);
+
+#endif // SVG_H_INCLUDED
diff --git a/text.cpp b/text.cpp
new file mode 100644
index 0000000..2b86204
--- /dev/null
+++ b/text.cpp
@@ -0,0 +1,48 @@
+#include "text.h"
+#include
+
+using namespace std;
+
+void
+static printspace (int number)
+{
+ if (number < 10) cout << " ";
+ else if (number < 100) cout << " ";
+}
+
+void
+show_histogram_text(const vector& bins, size_t bin_count)
+{
+ size_t max_count = 0;
+ for (int i = 0; i < bins.size(); i++)
+ {
+ if (bins[i] > max_count) max_count = bins[i];
+ }
+ if (max_count <= 76)
+ {
+ for (size_t i = 0; i < bin_count; i++)
+ {
+ printspace(bins[i]);
+ cout << bins[i] << "|";
+ for (size_t j = 0; j < bins[i]; j++)
+ {
+ cout << "*";
+ }
+ cout << endl;
+ }
+ }
+ else
+ {
+ for (size_t i = 0; i < bin_count; i++)
+ {
+ size_t height = 76 * (static_cast(bins[i]) / max_count);
+ printspace(bins[i]);
+ cout << bins[i] << "|";
+ for (size_t j = 0; j < height; j++)
+ {
+ cout << "*";
+ }
+ cout << endl;
+ }
+ }
+}
diff --git a/text.h b/text.h
new file mode 100644
index 0000000..535fac0
--- /dev/null
+++ b/text.h
@@ -0,0 +1,9 @@
+#ifndef TEXT_H_INCLUDED
+#define TEXT_H_INCLUDED
+
+#include
+
+void
+show_histogram_text(const std::vector& bins, size_t bin_count);
+
+#endif // TEXT_H_INCLUDED
diff --git a/unittest.cbp b/unittest.cbp
new file mode 100644
index 0000000..7f9621b
--- /dev/null
+++ b/unittest.cbp
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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..2c388d8
--- /dev/null
+++ b/unittest.depend
@@ -0,0 +1,60 @@
+# depslib dependency file v1.0
+1746383500 source:c:\users\krivo\desktop\lab03\unittest.cpp
+ "doctest.h"
+ "histogram_internal.h"
+
+1746383051 c:\users\krivo\desktop\lab03\doctest.h
+
+
+
+
+
+
+ "doctest_fwd.h"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+