code:Функция отображения гистограммы
Этот коммит содержится в:
@@ -64,6 +64,34 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
||||
return bins;
|
||||
}
|
||||
|
||||
void show_histogram_text(const vector<size_t>& bins, size_t screen_width = SCREEN_WIDTH) {
|
||||
const size_t MAX_ASTERISK = screen_width - 3 - 1;
|
||||
size_t max_count = bins[0];
|
||||
for (size_t count : bins) {
|
||||
if (count > max_count)
|
||||
max_count = count;
|
||||
}
|
||||
for (size_t j = 0; j < bins.size(); j++) {
|
||||
if (bins[j] < 100)
|
||||
cout << " ";
|
||||
if (bins[j] < 10)
|
||||
cout << " ";
|
||||
cout << bins[j] << "|";
|
||||
|
||||
size_t height = 0;
|
||||
if (max_count > MAX_ASTERISK) {
|
||||
height = static_cast<size_t>(static_cast<double>(bins[j]) / max_count * MAX_ASTERISK);
|
||||
}
|
||||
else {
|
||||
height = bins[j];
|
||||
}
|
||||
for (size_t i = 0; i < height; i++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
size_t number_count;
|
||||
|
||||
Ссылка в новой задаче
Block a user