diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..dcdd87a --- /dev/null +++ b/text.cpp @@ -0,0 +1,43 @@ +#include <vector> +#include "text.h" +#include <iostream> + +using namespace std; + +const int max_length = 80; // ������������ ����� +const int indent = 4; // ������ + + +void show_histogram_text(const vector<double> bins, size_t bin_count){ +double max_bin = bins[0]; + int k; + for (size_t i = 0; i < bin_count; i++) { // ���������� ���� �������� bin[] + if (bins[i] > max_bin) { + max_bin = bins[i]; + } + } + if (max_bin <= (max_length - indent)) { // ��������� ����� ������ "*" � ������������ ������ ��������� ������ + k = 0; + } + else { + k = 1; + } + + cerr << endl; + int out; + for (size_t i = 0; i < bin_count; i++) { + cout.width(3); // ������������ + cout.fill(' '); + cout << bins[i] << "|"; + if (k == 0) { // ��������������� + out = bins[i]; // ������� ����� + } + else { + out = bins[i] * (max_length - indent) / max_bin; // ���������������� ����� + } + for (int j = 0; j < out; j++) { + cout << "*"; + } + cout << endl; + } +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..155fcc1 --- /dev/null +++ b/text.h @@ -0,0 +1,4 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED +void show_histogram_text(const std::vector<double> bins, size_t bin_count); +#endif // TEXT_H_INCLUDED