#include #include #include #include "text.h" using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 4; void show_histogram_text(const vector& bins, size_t bin_count) { size_t max_count = bins[0]; for (size_t i = 0; i < bin_count; i++) { if (bins[i] > max_count) { max_count = bins[i]; } } vector height(bin_count); for (size_t i = 0; i < bin_count; i++) { if (max_count > MAX_ASTERISK) { height[i] = round(MAX_ASTERISK * (static_cast(bins[i]) / max_count)); } else { height[i] = bins[i]; } } for (size_t i = 0; i < bin_count; i++) { if (bins[i] < 10) { cout << " "; } else if (bins[i] < 100) { cout << " "; } cout << bins[i] << "| "; for (size_t j = 0; j < height[i]; j++) { cout << " * "; } cout << endl; } }