#include #include #include #include "text.h" #include "histogram.h" #include "histogram_internal.h" using namespace std; void svg_begin(double width, double height) { cout << "\n"; cout << "\n"; } void svg_end() { cout << "\n"; } void svg_text(double left, double baseline, string text) { cout << "" << text << "" << endl; } void svg_rect(double x, double y, double width, double height) { cout << "" << endl; } void show_histogram_svg(const vector bins) { svg_begin(400, 300); svg_text(20, 35, to_string(bins[0])); svg_rect(50, 0, bins[0] * 10, 30); svg_end(); } 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; } } }