Родитель
e080d18b72
Сommit
6cbf00d654
@ -0,0 +1,37 @@
|
||||
#include <vector>
|
||||
#include "text.h"
|
||||
#include "histogram.h"
|
||||
#include <iostream>
|
||||
void show_histogram_text(size_t bin_count, const std::vector<double>&numbers) {
|
||||
|
||||
std::vector <size_t> bins = make_histogram(numbers, bin_count);
|
||||
size_t height;
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
int max_count = 0;
|
||||
for (int i = 0; i < bin_count; i++) {
|
||||
if (bins[i] > max_count)
|
||||
max_count = bins[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < bin_count; i++) {
|
||||
if (bins[i] < 10) {
|
||||
std::cout << " ";
|
||||
}
|
||||
if (bins[i] < 100) {
|
||||
std::cout << " ";
|
||||
}
|
||||
std::cout << bins[i] << "|";
|
||||
if (max_count > 76) {
|
||||
height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
for (int b = 0; b < height; b++)
|
||||
std::cout << "*";
|
||||
}
|
||||
else {
|
||||
for (int b = 0; b < bins[i]; b++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче