diff --git a/main.cpp b/main.cpp index b0925aa..e933a88 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,9 @@ #include #include #include "histogram.h" +#include "text.h" using namespace std; -const size_t SCREEN_WIDTH = 80; -const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; - struct Input { vector numbers; size_t bin_count{}; @@ -31,38 +29,6 @@ input_data(){ return in; } /* -void -find_minmax(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; - } - } -} - -vector make_histogram(vector& numbers, size_t bin_count) { - double min, max; - find_minmax(numbers, min, max); - - vector bins(bin_count, 0); - double bin_size = (max - min) / bin_count; - - for (double number : numbers) { - size_t bin_index = bin_count - 1; // default to last bin - if (number < max) { - bin_index = static_cast((number - min) / bin_size); - } - bins[bin_index]++; - } - - return bins; -}*/ - void show_histogram_text(const vector& bins){ size_t i; @@ -97,7 +63,7 @@ show_histogram_text(const vector& bins){ cout< + +void +show_histogram_text(std::vector& bins){ + size_t max_count = 0; + for (size_t x: bins) { + if (x > max_count) { + max_count = x; + } + } + if (max_count > MAX_ASTERISK) { + for(size_t bin:bins){ + size_t height = bin; + height = MAX_ASTERISK * (static_cast(bin) / max_count); + for(size_t i = 0; i < height; i++){ + std::cout<<"*"; + } + std::cout<<"|"; + if(bin<100) std::cout<<" "; + if(bin<10) std::cout<<" "; + std::cout< + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + +void +show_histogram_text(std::vector& bins); + +#endif // TEXT_H_INCLUDED