From c2d6094820972daacda0364f9896fd8b933d7da5 Mon Sep 17 00:00:00 2001 From: "Nastya (PozdiayevaAV)" Date: Fri, 31 Oct 2025 11:04:54 +0300 Subject: [PATCH] first commit --- histogram_internal.h | 6 ++++++ text.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ text.h | 6 ++++++ unittest.cbp | 38 ++++++++++++++++++++++++++++++++++++++ unittest.cpp | 13 +++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 histogram_internal.h create mode 100644 text.cpp create mode 100644 text.h create mode 100644 unittest.cbp create mode 100644 unittest.cpp diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..96926c5 --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1,6 @@ +#ifndef HISTOGRAM_INTERNAL_H_INCLUDED +#define HISTOGRAM_INTERNAL_H_INCLUDED +#include +void find_minmax( const std::vector& numbers, double& minN, double& maxN); + +#endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..08bf2ee --- /dev/null +++ b/text.cpp @@ -0,0 +1,41 @@ +#include "text.h" +#include +#include +using namespace std; +void show_histogram_text(const vector & bins,size_t bin_count, size_t max_count){ + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1; + + bool scaling = false; + + if (max_count > MAX_ASTERISK){ + scaling = true; + } + + for (size_t i = 0; i < bin_count; i++){ + cout << " "; + if (bins[i] < 100){ + cout << ' '; + } + if (bins[i] < 10){ + cout << ' '; + } + cout << bins[i] << '|'; + + size_t number_of_stars = bins[i]; + + if (scaling){ + if (bins[i] == max_count){ + number_of_stars = MAX_ASTERISK * 1.0; + } + else { + number_of_stars = MAX_ASTERISK * (static_cast(bins[i]) / max_count); + } + } + + for (size_t j = 0; j < number_of_stars; j++){ + cout << '*'; + } + cout << endl; + } +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..a619492 --- /dev/null +++ b/text.h @@ -0,0 +1,6 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED +#include +void show_histogram_text(const std::vector & bins,size_t bin_count, size_t max_count); + +#endif // TEXT_H_INCLUDED diff --git a/unittest.cbp b/unittest.cbp new file mode 100644 index 0000000..7f9621b --- /dev/null +++ b/unittest.cbp @@ -0,0 +1,38 @@ + + + + + + diff --git a/unittest.cpp b/unittest.cpp new file mode 100644 index 0000000..13c8df0 --- /dev/null +++ b/unittest.cpp @@ -0,0 +1,13 @@ +#define DOCTEST_CONFIG_NO_MULTITHREADING +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest.h" +#include "histogram_internal.h" +#include "histogram.h" + +TEST_CASE("distinct positive numbers") { + double minN = 0; + double maxN = 0; + find_minmax({1, 2}, minN, maxN); + CHECK(minN == 1); + CHECK(maxN == 2); +}