#include "text.h" using namespace std; void show_histogram_text(vector& bins, size_t bin_count) { const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; // Поиск максимального количесва оценок в одном столбце. size_t max_count = bins[0]; for (size_t i = 0; i < bin_count; i++) { if (bins[i] > max_count) max_count = bins[i]; } // Создание гистограммы по оценкам. size_t height; size_t buf; for (size_t i = 0; i < bin_count; i++) { buf = bins[i]; while (buf < max_count) // Выравнивание для чисел, меньших чем максимальное число. { cout << " "; buf *= 10; } cout << bins[i] << "|"; height = bins[i]; if (max_count > MAX_ASTERISK) height = MAX_ASTERISK * (static_cast(bins[i]) / max_count); for (size_t j = 1; j <= height; j++) cout << "*"; cout << endl; } }