diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..418e3d5 --- /dev/null +++ b/text.cpp @@ -0,0 +1,40 @@ +#include "text.h" +#include +#include +void show_histogram_text(std::vector bins, size_t bin_count) +{ + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + double max_count = bins[0]; + for (double x : bins) { + if (x > max_count) { + max_count = x; + } + } + size_t height; + bool flag = true; + for (size_t j = 0; j < bin_count; j++) { + if (bins[j] < 100) { + std::cout << " "; + } + if (bins[j] < 10) { + std::cout << " "; + } + std::cout << bins[j] << "|"; + if (max_count > MAX_ASTERISK) { + for (size_t i = 0; i < bins[j]; i++) { + if (bins[j] != MAX_ASTERISK && flag) { + double count = bins[j]; + height = MAX_ASTERISK * (static_cast(count) / max_count); + bins[j] = height; + flag = false; + } + } + } + for (size_t i = 0; i < bins[j]; i++) { + std::cout << "*"; + } + std::cout << std::endl; + flag = true; + } +} \ No newline at end of file