diff --git a/main.cpp b/main.cpp index b0a1039..4c675d2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,9 @@ #include #include +#include "histogram.h" +#include "text.h" +#include "svg.h" using namespace std; - -const size_t SCREEN_WIDTH = 80; -const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1; - struct Input { vector numbers; size_t bin_count{}; @@ -27,70 +26,8 @@ input_data(){ return in; } -void -find_minmax(const vector& numbers, double& min, double& max){ - min = numbers[0]; - max = numbers[0]; - for (double x: numbers){ - if (min > x){ - min = x; - } - if (max < x){ - max = x; - } - } -} - -vector make_histogram(const vector& numbers, size_t bin_count){ - double min, max; - vector bins(bin_count); - find_minmax(numbers, min, max); - double diff = (max - min) / bin_count; - size_t max_count = 0; - for (double x: numbers){ - bool found = false; - for (size_t j = 0;(j < bin_count - 1) && !found; j++){ - auto lo = min + j * diff; - auto hi = min + (j + 1) * diff; - if ((lo <= x) && (hi > x)){ - bins[j]++; - found = true; - } - } - if(!found){ - bins[bin_count - 1]++; - if (bins[bin_count - 1] > max_count){ - max_count = bins[bin_count - 1]; - } - } - } - return bins; -} - -void show_histogram_text(const vector& bins){ - for (double x: bins){ - cout << " "; - if (x < 100){ - cout << " "; - } - if (x < 10){ - cout << " "; - } - cout << x << "|"; - - size_t number_of_stars = x; - - for (size_t j = 0; j < number_of_stars; j++){ - cout << "*"; - } - cout << endl; - } - -} - - int main(){ auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins); + show_histogram_svg(bins); }