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