diff --git a/main.cpp b/main.cpp index 753abb6..0f6ddd2 100644 --- a/main.cpp +++ b/main.cpp @@ -44,53 +44,46 @@ find_minmax(vector numbers, double& min, double& max) return; } - - - - - -int main() +auto make_histogram (vector numbers, size_t bin_count) { - - const size_t screen_width = 80; - const size_t max_asterisk = screen_width - 3 - 1; - int i, j; - - - Input in = input_data(); - - - - vector bins(in.bin_count); - double min; double max; - find_minmax (in.numbers, min, max); - - double bin_size = (max - min) / in.bin_count; + find_minmax (numbers, min, max); + double bin_size = (max - min) / bin_count; + vector bins(bin_count); - for (size_t i = 0; i < in.numbers.size(); i++) + for (size_t i = 0; i < numbers.size(); i++) { bool found = false; - for (size_t j = 0; (j < in.bin_count - 1) && !found; j++) + 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 <= in.numbers[i]) && (in.numbers[i] < hi)) + if ((lo <= numbers[i]) && (numbers[i] < hi)) { - bins[j] ++; + bins[j]++; found = true; } } + if (!found) { - bins[in.bin_count - 1]++; + bins[bin_count - 1]++; } } + return bins; +} + + +void show_histogram_text(auto bins, size_t bin_count) +{ + const size_t screen_width = 80; + const size_t max_asterisk = screen_width - 3 - 1; + size_t i,j; double max_count; max_count = bins[0]; - for (i=0; i< in.bin_count; i++) + for (i=0; i< bin_count; i++) { if (max_count