diff --git a/lab01.cpp b/lab01.cpp index 6c34053..5a62543 100644 --- a/lab01.cpp +++ b/lab01.cpp @@ -2,6 +2,10 @@ #include #include #include +#include "histogram.h" +#include "text.h" +#include "svg.h" + using namespace std; @@ -16,99 +20,6 @@ input_numbers(size_t count) { } - -void -find_minmax(const vector& numbers, double& min, double& max) { - min = numbers[0]; - max = numbers[0]; - for (double number : numbers) - { - if (number < min) - { - min = number; - } - - if (number > max) - { - max = number; - } - } - return; -} - -vector make_histogram(const vector& numbers, const size_t bin_count) -{ - double min, max; - find_minmax(numbers, min, max); - double bin_size = (max - min) / bin_count; - vector bins(bin_count, 0); - for (size_t i = 0; i < numbers.size(); i++) - { - bool found = false; - for (size_t j = 0; j < bin_count - 1 && !found; j++) - { - auto lo = min + j * bin_size; - auto hi = min + (j + 1) * bin_size; - - if (lo <= numbers[i] && numbers[i] < hi) - { - bins[j]++; - found = true; - } - } - if (!found) - { - bins[bin_count - 1]++; - } - } - return bins; -} - -void show_histogram_text(const vector& bins) -{ - const size_t SCREEN_WIDTH = 80; - const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; - - size_t max_bin = bins[0]; - for (double bin : bins) - { - if (bin > max_bin) - { - max_bin = bin; - } - } - - for (size_t bin : bins) - { - size_t height = bin; - // проверить масштабирование(пересчитать height) - - if (max_bin > MAX_ASTERISK) - { - height = MAX_ASTERISK * (static_cast (bin) / max_bin); - } - - - if (bin < 100) { - cout << " "; - } - - if (bin < 10) { - cout << " "; - } - - cout << bin << "|"; - - - for (size_t i = 0; i < height; i++) - { - cout << "*"; - } - cout << endl; - - } -} - int main() { @@ -122,11 +33,11 @@ int main() size_t bin_count; cerr << "Enter bin count: "; cin >> bin_count; - //расчет данных const auto bins = make_histogram(numbers, bin_count); - show_histogram_text(bins); + //show_histogram_text(bins,bin_count);// + show_histogram_svg(bins, number_count, bin_count); return 0; }