#include #include #include "text.h" using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; void show_histogram_text(const vector &bins) { size_t maxCount = bins[0]; for (auto bin : bins) { if (maxCount < bin) { maxCount = bin; } } for (auto bin : bins) { if (bin < 100) { cout << " "; } if (bin < 10) { cout << " "; } size_t height = maxCount < MAX_ASTERISK ? bin : MAX_ASTERISK * (static_cast(bin) / maxCount); cout << bin << "|"; for (size_t j = 0; j < height; j++) { cout << "*"; } cout << "\n"; } }