code: Добавлен вывод гистограммы

main
YusufovYB 2 лет назад
Родитель d9c7665954
Сommit 29407d722c

@ -38,8 +38,8 @@ void find_minmax( const vector<double>& numbers, double& minimum, double& maximu
double maximum, minimum; double maximum, minimum;
float LL, LR; float LL, LR;
double bin_size = (maximum - minimum) / bin_count;
find_minmax(numbers, minimum, maximum); find_minmax(numbers, minimum, maximum);
double bin_size = (maximum - minimum) / bin_count;
vector <size_t> bins(bin_count); vector <size_t> bins(bin_count);
LL = minimum; LL = minimum;
LR = minimum + bin_size; LR = minimum + bin_size;
@ -72,27 +72,19 @@ void find_minmax( const vector<double>& numbers, double& minimum, double& maximu
} }
return bins; return bins;
} }
void show_histogram_text(size_t bin_count, const vector<double>&numbers) {
int main() { vector <size_t> bins = make_histogram(numbers, bin_count);
auto in = input_data(); size_t height;
auto bins = make_histogram(in.numbers,in.bin_count);
const size_t SCREEN_WIDTH = 80; const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
max_count = 0; int max_count = 0;
for (int i = 0; i < bin_count; i++) { for (int i = 0; i < bin_count; i++) {
if (bins[i] > max_count) if (bins[i] > max_count)
max_count = bins[i]; max_count = bins[i];
} }
for (int i = 0; i < bin_count; i++) { for (int i = 0; i < bin_count; i++) {
if ((i + 1) < bin_count)
he_next = bins[i + 1];
else
he_next = -1;
if (bins[i] < 10) { if (bins[i] < 10) {
cout << " "; cout << " ";
} }
@ -102,33 +94,25 @@ int main() {
cout << bins[i] << "|"; cout << bins[i] << "|";
if (max_count > 76) { if (max_count > 76) {
height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count); height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
if ((i+1) < bin_count) for (int b = 0; b < height; b++)
he2_next = MAX_ASTERISK * (static_cast<double>(bins[i + 1]) / max_count);
else
he2_next = -1;
for (int b = 0; b < height; b++) {
if (b == he2_previous)
cout << "^";
if (b == he2_next)
cout << "˅";
if ((b != (he2_previous - 1)) && (b != (he2_next - 1)))
cout << "*"; cout << "*";
} }
he2_previous = height;
}
else { else {
for (int b = 0; b < bins[i]; b++) { for (int b = 0; b < bins[i]; b++) {
if (b == (he_previous-1))
cout << "^";
if (b == (he_next - 1))
cout << "v";
if ((b != (he_previous - 1)) && (b != (he_next - 1)))
cout << "*"; cout << "*";
} }
} }
cout << endl; cout << endl;
he_previous = bins[i];
} }
}
int main() {
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(in.bin_count, in.numbers);
return 0; return 0;
} }

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