#include #include #include #include #include #include "histogram.h" using namespace std; //!Разделить программу на файлы (3 пункт)! //Создание структуры Input для входных данных struct Input { vector Numbers; size_t bin_count{}; }; //Функция ввода Input input_data(){ size_t number_count; Input stct; //Ввод количества элементов массива cerr << "Enter number count "; cin >> number_count; //Ввод массива vector Numbers(number_count); stct.Numbers.resize(number_count); cerr << "Enter array:\n"; cin >> Numbers[0]; for (int i = 1; i < number_count; i++) { cin >> stct.Numbers[i]; } //Ввод количества корзин cerr << "Enter bin count\n"; cin >> stct.bin_count; //Возвращаем структуру return stct; } //Функция отображения и масштабирования гистограммы void show_histogram_text(const vector& bins){ const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 3; //Проверка необходимости масшатбирования size_t max4scale = 0; for (size_t x : bins){ if (x > max4scale){ max4scale = x; } } if (max4scale > MAX_ASTERISK){ for (size_t x : bins) { if (x >= 100){ cout << x << " | "; } else if (x >= 10){ cout << " " << x << " | "; } else{ cout << " " << x << " | "; } size_t count = x; size_t height = MAX_ASTERISK * (static_cast(count) / max4scale); for (size_t i = 0; i < height; i++) { cout << "*"; } cout << "\n"; } } else{ //Вывод for (size_t x : bins) { if (x >= 100){ cout << x << " | "; } else if (x >= 10){ cout << " " << x << " | "; } else{ cout << " " << x << " | "; } for (size_t i = 0; i < x; i++) { cout << "*"; } cout << "\n"; } } return; } int main() { //Ввод массива и количества корзин Input in = input_data(); //Создание вектора bins для гистограммы vector bins = make_histogram(in.Numbers, in.bin_count); //Вывод гистограммы show_histogram_text(bins); return 0; }