diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c7473d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin +/obj diff --git a/hist_proc.h b/hist_proc.h new file mode 100644 index 0000000..ae505d2 --- /dev/null +++ b/hist_proc.h @@ -0,0 +1,7 @@ +#ifndef HIST_PROC_H_INCLUDED +#define HIST_PROC_H_INCLUDED + +std::vector +make_histogram_proc(const std::vector numbers, size_t bin_count, std::vector bins); + +#endif // HIST_PROC_H_INCLUDED diff --git a/histogram.h b/histogram.h new file mode 100644 index 0000000..aab82b8 --- /dev/null +++ b/histogram.h @@ -0,0 +1,9 @@ +#ifndef HISTOGRAM_H_INCLUDED +#define HISTOGRAM_H_INCLUDED +#include +#include + +std::vector +make_histogram(const std::vector numbers, size_t bin_count); + +#endif // HISTOGRAM_H_INCLUDED diff --git a/lab003.cbp b/lab003.cbp index 45b22cf..bce77cc 100644 --- a/lab003.cbp +++ b/lab003.cbp @@ -38,6 +38,10 @@ + + + diff --git a/main.cpp b/main.cpp index 97ef452..b71ca3a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "histogram.h" #include diff --git a/svg.cpp b/svg.cpp index 94f000c..11e48d9 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,5 +1,6 @@ #include #include +#include #include using namespace std; @@ -19,8 +20,59 @@ 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){ + cout << "\n"; +} + 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; + const double SCALE = IMAGE_WIDTH - TEXT_WIDTH; svg_begin(400, 300); + + + double max_count = 0; + for (double x: bins) { + if (x > max_count) { + max_count = x; + } + } + double top = 0; + if ((max_count*BLOCK_WIDTH)>SCALE){ + for (size_t bin : bins) { + const double bin_width = SCALE * ( bin / max_count); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + top += BIN_HEIGHT; + cout << endl; + cout << bin_width; + } + } + else{ + 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); + top += BIN_HEIGHT; + cout << endl; + cout << bin_width; +} + } svg_end(); + } + + + diff --git a/svg.h b/svg.h index 0c45c32..ac36df3 100644 --- a/svg.h +++ b/svg.h @@ -1,12 +1,6 @@ #ifndef SVG_H_INCLUDED #define SVG_H_INCLUDED -void -svg_begin(double width, double height); - -void -svg_end(); - void show_histogram_svg(const std::vector& bins); diff --git a/text.h b/text.h new file mode 100644 index 0000000..a7006f9 --- /dev/null +++ b/text.h @@ -0,0 +1,7 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED + +void +show_histogram(size_t bin_count, std::vector bins, std::vector procent); + +#endif // TEXT_H_INCLUDED