#include #include #include "text.h" #include "histogram.h" #include "histogram_internal.h" using namespace std; void show_histogram_text(const vector bins, const size_t bin_count) { // Максимальное в коорзинах const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; int max_in_bins = 0; for (int i = 0; i < bin_count; i++) { if (bins[i] > max_in_bins) { max_in_bins = bins[i]; } } if (max_in_bins > MAX_ASTERISK) { for (int i = 0; i < bin_count; i++) { if (bins[i] < 100) { cout << " "; } if (bins[i] < 10) { cout << " "; } size_t height = MAX_ASTERISK * (static_cast(bins[i]) / max_in_bins); cout << bins[i] << "|"; for (int j = 0; j < height; j++) { cout << "*"; } cout << endl; } } else { // Если максимальное число среди коорзин меньше или равно 76 for (int i = 0; i < bin_count; i++) { if (bins[i] < 100) { cout << " "; } if (bins[i] < 10) { cout << " "; } cout << bins[i] << "|"; for (int j = 0; j < bins[i]; j++) { cout << "*"; } cout << endl; } } }