Родитель
58bc515f9b
Сommit
3854b115fa
@ -1,8 +1,40 @@
|
|||||||
//
|
#include "text.h"
|
||||||
// text.cpp
|
#include <iostream>
|
||||||
// lab01
|
|
||||||
//
|
using namespace std;
|
||||||
// Created by Светлана Рыбакова on 01.05.2025.
|
|
||||||
//
|
void show_histogram_text(const vector<size_t>& bins) {
|
||||||
|
const size_t SCREEN_WIDTH = 80;
|
||||||
#include <stdio.h>
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 4;
|
||||||
|
|
||||||
|
size_t max_bin_count = 0;
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
if (bin > max_bin_count) {
|
||||||
|
max_bin_count = bin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_bin_count <= MAX_ASTERISK) {
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
if (bin < 10) cout << " ";
|
||||||
|
cout << " " << bin << "|";
|
||||||
|
for (size_t j = 0; j < bin; j++) {
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bin) / max_bin_count));
|
||||||
|
|
||||||
|
if (bin < 100) cout << " ";
|
||||||
|
if (bin < 10) cout << " ";
|
||||||
|
cout << bin << "|";
|
||||||
|
|
||||||
|
for (size_t j = 0; j < height; j++) {
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
//
|
#ifndef TEXT_H_INCLUDED
|
||||||
// text.h
|
#define TEXT_H_INCLUDED
|
||||||
// lab01
|
|
||||||
//
|
|
||||||
// Created by Светлана Рыбакова on 01.05.2025.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef text_h
|
#include <vector>
|
||||||
#define text_h
|
|
||||||
|
|
||||||
|
void show_histogram_text(const std::vector<size_t>& bins);
|
||||||
|
|
||||||
#endif /* text_h */
|
#endif // TEXT_H_INCLUDED
|
||||||
|
Загрузка…
Ссылка в новой задаче