#include #include #include #include "histogram.h" using namespace std; struct Input { vector numbers; size_t bin_count{}; size_t SCREEN_WIDTH{}; size_t number_count{}; }; Input input_data() { Input in; cerr << "Enter number count: "; cin >> in.number_count; in.numbers.resize(in.number_count); for (size_t i = 0; i < in.number_count; i++) { cin >> in.numbers[i]; } cerr<<"Enter bin count:"; cin >> in.bin_count; while (true) { cerr << "Screen width: "; cin >> in.SCREEN_WIDTH; if (in.SCREEN_WIDTH < 7) { cerr << "<7"; cerr << endl; continue; } if (in.SCREEN_WIDTH > 80) { cerr << ">80"; cerr << endl; continue; } if (in.SCREEN_WIDTH < (in.number_count / 3)){ cerr << "& bins, size_t MAX_ASTERISK, size_t bin_count) { double mxbins = bins[0]; for (double x : bins) { if (x > mxbins) mxbins = x; } double k; if (mxbins > MAX_ASTERISK) k = MAX_ASTERISK / mxbins; else k = 1; for (size_t i = 0; i < bin_count; i++) { if (bins[i] < 10) { cout << " " << bins[i] << "|"; } else if (bins[i] < 100) { cout << " " << bins[i] << "|"; } else if (bins[i] < 1000) { cout << bins[i] << "|"; } for (int j = 0; j < floor(bins[i] * k); j++) { cout << "*"; } cout << endl; } } int main() { auto in = input_data(); double min, max; const size_t MAX_ASTERISK = in.SCREEN_WIDTH - 3 - 1; auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_text(bins, MAX_ASTERISK, in.bin_count); }