code: разбиение на файлы

master
Alice (TimoshenkoAA) 1 год назад
Родитель fa9fc93b8a
Сommit f983a55f15

@ -19,10 +19,13 @@ input_data() {
for (size_t i = 0; i < number_count; i++) { for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i]; cin >> in.numbers[i];
} }
cerr << "Enter bin count: "; cerr << "Enter bin count: ";
cin >> in.bin_count; cin >> in.bin_count;
return in; return in;
} }
void void
find_minmax(const vector<double>& numbers, double& min, double& max) { find_minmax(const vector<double>& numbers, double& min, double& max) {
min = numbers[0]; min = numbers[0];
@ -36,15 +39,16 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
} }
} }
} }
vector <double> vector <double>
make_histogram(const vector<double>& numbers, size_t bin_count){ make_histogram(const vector<double>& numbers, size_t bin_count){
vector<double> bins (bin_count); vector<double> bins (bin_count);
double min = 0, max = 0; double min = 0, max = 0;
find_minmax(numbers, min, max); find_minmax(numbers, min, max);
double bin_size = (max - min) / bin_count; double bin_size = (max - min) / bin_count;
for (int i = 0; i < numbers.size(); i++) { for (int i = 0; i < numbers.size(); i++) {
bool found = false; bool found = false;
for (int j = 0; (j < bin_count - 1) && !found; j++) { for (int j = 0; (j < bin_count - 1) && !found; j++) {
auto lo = min + j * bin_size; auto lo = min + j * bin_size;
@ -63,13 +67,13 @@ make_histogram(const vector<double>& numbers, size_t bin_count){
void void
show_histogram_text (const vector<double>& bins,size_t MAX_ASTERISK, size_t bin_count){ show_histogram_text (const vector<double>& bins,size_t MAX_ASTERISK, size_t bin_count){
double max_count = bins[0]; double max_count = bins[0];
for (double x: bins){ for (double x: bins){
if (x > max_count) { if (x > max_count) {
max_count = x; max_count = x;
} }
} }
for (int i = 0; i < bin_count; i++){ for (int i = 0; i < bin_count; i++){
double count = bins[i]; double count = bins[i];
size_t height = MAX_ASTERISK * (static_cast<double>(count) / max_count); size_t height = MAX_ASTERISK * (static_cast<double>(count) / max_count);

Загрузка…
Отмена
Сохранить