#include #include #include "histogram.h" #include "text.h" #include "svg.h" using namespace std; struct Input { vector numbers; size_t bin_count; size_t image_width; }; Input input_data() { Input in; size_t number_count; cerr << "Enter number count: "; cin >> number_count; in.numbers.resize(number_count); cerr << "Enter numbers: "; for (size_t i = 0; i < number_count; i++) { cin >> in.numbers[i]; } cerr << "Enter bin count: "; cin >> in.bin_count; const size_t BLOCK_WIDTH = 10; const size_t MIN_WIDTH = 70; const size_t MAX_WIDTH = 800; size_t required_min_width = number_count * BLOCK_WIDTH / 3; while (true) { cerr << "Enter image width (" << MIN_WIDTH << "-" << MAX_WIDTH << "), minimum " << required_min_width << ": "; cin >> in.image_width; if (in.image_width < MIN_WIDTH) { cerr << "Width is too small (minimum " << MIN_WIDTH << ")\n"; } else if (in.image_width > MAX_WIDTH) { cerr << "Width is too large (maximum " << MAX_WIDTH << ")\n"; } else if (in.image_width < required_min_width) { cerr << "Width is less than 1/3 of numbers count * block width (" << required_min_width << ")\n"; } else { break; } } return in; } int main() { auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins, in.image_width); return 0; }