diff --git a/histogram.cpp b/histogram.cpp index da61b14..6aceb65 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,7 +1,7 @@ #include #include "histogram.h" using namespace std; -static void find_minmax(const vector& numbers, double& min, double& max) +void find_minmax(const vector& numbers, double& min, double& max) { min = numbers[0]; max = numbers[0]; diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..5cd1715 --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1,6 @@ +#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/laba.cbp b/laba.cbp index 5d9994f..a58db8a 100644 --- a/laba.cbp +++ b/laba.cbp @@ -32,7 +32,22 @@ + + + + + + + + + + + diff --git a/main.cpp b/main.cpp index b6e27d9..72a5d83 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include "histogram.h" #include "text.h" +#include "svg.h" using namespace std; struct Input{ @@ -32,6 +33,6 @@ int main() { auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins); + show_histogram_svg(bins); return 0; } 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/svg.cpp b/svg.cpp new file mode 100644 index 0000000..f9b348c --- /dev/null +++ b/svg.cpp @@ -0,0 +1,61 @@ +#include "svg.h" +#include +#include +#include +using namespace std; + +void +svg_begin(double width, double height) { + cout << "\n"; + cout << "\n"; +} + +void +svg_end() { + 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) { + 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(IMAGE_WIDTH, IMAGE_HEIGHT); + + size_t max_count = bins[0]; + for(size_t x: bins){ + if(x > max_count){ + max_count = x; + } + } + double top = 0; + for (size_t bin : bins) { + const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH) * bin / max_count; + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "blue"); + top += BIN_HEIGHT; + } + svg_end(); +} + + diff --git a/svg.h b/svg.h new file mode 100644 index 0000000..8e4cab3 --- /dev/null +++ b/svg.h @@ -0,0 +1,10 @@ +#ifndef SVG_H_INCLUDED +#define SVG_H_INCLUDED +#include + + +void +show_histogram_svg(const std::vector& bins); + + +#endif // SVG_H_INCLUDED diff --git a/text.h b/text.h index 56dc36a..2a549ae 100644 --- a/text.h +++ b/text.h @@ -2,7 +2,6 @@ #define TEXT_H_INCLUDED #include - void show_histogram_text(const std::vector& bins); diff --git a/unittest.cbp b/unittest.cbp new file mode 100644 index 0000000..d291579 --- /dev/null +++ b/unittest.cbp @@ -0,0 +1,39 @@ + + + + + + diff --git a/unittest.cpp b/unittest.cpp new file mode 100644 index 0000000..e783068 --- /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 , -5}, min, max); + CHECK(min == -3); + CHECK(max == -1); +}