#include "text.h" #include #include using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; void show_histogram_text(vector bins) { size_t maxb = 0; for (int i = 0;i < bins.size();i++) { if (bins[i] > maxb) { maxb = bins[i]; } } double k = double(MAX_ASTERISK) / maxb; if (k > 1) { k = 1; } vector bin_graph(bins.size()); for (size_t bin = 0; bin < bins.size(); bin++) { bin_graph[bin] = int(double(bins[bin] * k)); } for (size_t i = 0; i < bins.size(); i++) { if (bins[i] < 100) { cout << " "; } if (bins[i] < 10) { cout << " "; } cout << bins[i] << '|'; for (size_t j = 0;j < bin_graph[i];j++) { cout << "*"; } cout << endl; } }