#include "text.h" #include #include using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_LENGTH = SCREEN_WIDTH - 3 - 1; void show_histogram_text(vector bins, size_t bin_count ){ auto max_count = bins[0]; for (auto x : bins) { if (x > max_count) { max_count = x; } } for (size_t i = 0; i < bin_count; i++) { size_t j = 100; while (bins[i] < j) { cout << " "; j /= 10; } cout << bins[i] << "|"; if (max_count > MAX_LENGTH) { auto count = bins[i]; size_t height = MAX_LENGTH * (static_cast(count) / max_count); j = 0; while (j < height) { cout << "*"; j++; } } else { j = 0; while (j < bins[i]) { cout << "*"; j++; } } cout << endl; } }