diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..86b58fd --- /dev/null +++ b/text.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include "text.h" +using namespace std; +void +show_histogram_text(const vector bins, size_t bin_count){ + const size_t MAX_ELEMENT = 76; + double max_count = bins[0]; + for (size_t j=0; j < bin_count; j++){ + if (bins[j] > max_count) { + max_count = bins[j]; + } + } + vector height(bin_count); + for (size_t j=0; j < bin_count; j++){ + height[j] = MAX_ELEMENT * (bins[j]/max_count); + } + + if (max_count > MAX_ELEMENT){ + for (size_t j=0; j < bin_count; j++) + { + if (bins[j] < 100) { + cout << " "; + if (bins[j] < 10){ + cout << " "; + } + } + cout << bins[j] << "|"; + + for (size_t i=0; i < height[j]; i++){ + cout << "*"; + } + cout << endl; + } + } + else { + for (size_t j=0; j < bin_count; j++) + { + if (bins[j] < 100) { + cout << " "; + if (bins[j] < 10){ + cout << " "; + } + } + cout << bins[j] << "|"; + + for (size_t i=0; i < bins[j];i++){ + cout << "*"; + } + cout << endl; + } + } +}