diff --git a/histogram.cpp b/histogram.cpp index 857de96..344f24d 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,4 +1,5 @@ #include +#include #include "histogram.h" using namespace std; diff --git a/histogram.h b/histogram.h index 0d8dc8c..37cf761 100644 --- a/histogram.h +++ b/histogram.h @@ -3,7 +3,7 @@ #include -std::vector -make_histogram(const std::vector& numbers, size_t bin_count); +std::vector +make_histogram(const std::vector& numbers, std::size_t bin_count); #endif // HISTOGRAM_H_INCLUDED diff --git a/main.cpp b/main.cpp index 4550c63..5a6b998 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,11 @@ #include #include #include "histogram.h" +#include "text.h" using namespace std; -const size_t SCREEN_WIDTH = 80; -const size_t MAX_ASTERISK = SCREEN_WIDTH - 4; + struct Input { vector numbers; @@ -32,35 +32,6 @@ Input input_data() { return in; }; -void show_histogram_text(const vector &bins){ - size_t maxbin = bins[0]; - for (size_t i=1; i < bins.size(); i++){ - if (maxbin < bins[i]){ - maxbin = bins[i]; - } - } - - if (maxbin <= MAX_ASTERISK){ - for (size_t i = 0; i < bins.size(); i++) { - cout.width(4); - cout << bins[i] << "|"; - for (size_t j = 0; j < bins[i]; j++) { - cout << "*"; - } - cout << endl; - } - } else { - for (size_t i = 0; i < bins.size(); i++) { - cout.width(4); - cout << bins[i] << "|"; - size_t height = static_cast(MAX_ASTERISK * (static_cast(bins[i]) / maxbin)); - for (size_t j = 0; j < height; j++) { - cout << "*"; - } - cout << endl; - } - } -} int main(){ Input in = input_data(); diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..bc947fc --- /dev/null +++ b/text.cpp @@ -0,0 +1,38 @@ +#include +#include +#include "text.h" + +using namespace std; + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 4; + +void show_histogram_text(const vector &bins){ + size_t maxbin = bins[0]; + for (size_t i=1; i < bins.size(); i++){ + if (maxbin < bins[i]){ + maxbin = bins[i]; + } + } + + if (maxbin <= MAX_ASTERISK){ + for (size_t i = 0; i < bins.size(); i++) { + cout.width(4); + cout << bins[i] << "|"; + for (size_t j = 0; j < bins[i]; j++) { + cout << "*"; + } + cout << endl; + } + } else { + for (size_t i = 0; i < bins.size(); i++) { + cout.width(4); + cout << bins[i] << "|"; + size_t height = static_cast(MAX_ASTERISK * (static_cast(bins[i]) / maxbin)); + for (size_t j = 0; j < height; j++) { + cout << "*"; + } + cout << endl; + } + } +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..9a3bae6 --- /dev/null +++ b/text.h @@ -0,0 +1,9 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED + +#include + +std::vector +show_histogram_text(const std::vector & bins); + +#endif // TEXT_H_INCLUDED