Родитель
58bc515f9b
Сommit
3854b115fa
@ -1,8 +1,40 @@
|
||||
//
|
||||
// text.cpp
|
||||
// lab01
|
||||
//
|
||||
// Created by Светлана Рыбакова on 01.05.2025.
|
||||
//
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <stdio.h>
|
||||
using namespace std;
|
||||
|
||||
void show_histogram_text(const vector<size_t>& bins) {
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
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 @@
|
||||
//
|
||||
// text.h
|
||||
// lab01
|
||||
//
|
||||
// Created by Светлана Рыбакова on 01.05.2025.
|
||||
//
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
|
||||
#ifndef text_h
|
||||
#define text_h
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_text(const std::vector<size_t>& bins);
|
||||
|
||||
#endif /* text_h */
|
||||
#endif // TEXT_H_INCLUDED
|
||||
|
Загрузка…
Ссылка в новой задаче