diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..be24107 --- /dev/null +++ b/text.cpp @@ -0,0 +1,39 @@ +#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; + } +}