From 9d2dccc55bcbea96d3ee42f9fbf3d4194cba751b Mon Sep 17 00:00:00 2001 From: StepanovAV Date: Sat, 18 May 2024 11:48:26 +0000 Subject: [PATCH] revert 32335cc93c33631f69f2d561cac0aa74e4fdced4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit revert code: добавлен исправленный вариант общего кода --- lab34/histogram.cpp | 45 --------------------------------- lab34/histogram.h | 6 ----- lab34/lab34.cbp | 43 -------------------------------- lab34/main.cpp | 35 -------------------------- lab34/svg.cpp | 61 --------------------------------------------- lab34/svg.h | 5 ---- lab34/text.cpp | 43 -------------------------------- lab34/text.h | 5 ---- 8 files changed, 243 deletions(-) delete mode 100644 lab34/histogram.cpp delete mode 100644 lab34/histogram.h delete mode 100644 lab34/lab34.cbp delete mode 100644 lab34/main.cpp delete mode 100644 lab34/svg.cpp delete mode 100644 lab34/svg.h delete mode 100644 lab34/text.cpp delete mode 100644 lab34/text.h diff --git a/lab34/histogram.cpp b/lab34/histogram.cpp deleted file mode 100644 index 44da864..0000000 --- a/lab34/histogram.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "histogram.h" -#include -#include -#include - -void -find_minmax(const std::vector& numbers, double& min, double& max, bool& res){ - if (numbers.size() == 0){ - res = false; - return; - } - min = numbers[0]; - max = numbers[0]; - for (auto x : numbers) { - if (x < min) { - min = x; - } - else if (x > max) { - max = x; - } - } -} -std::vector -make_histogram(const std::vector& numbers, size_t bin_count){ - double min, max; - bool res = true; - find_minmax (numbers, min, max, res); - if (res == false){ - std::cerr << "Number of elements cannot be equal to zero"; - exit(1); - } - double bin_size = (max - min) / bin_count; - std::vector bins(bin_count); - for (auto x : numbers) { - bool found = false; - for (size_t j = 0; (j < bin_count - 1) && !found ; j++) { - if ((min + j * bin_size <= x) && (x < min + (j + 1) * bin_size)) { - bins[j] += 1; - found = true; - } - } - if (!found) bins[bin_count - 1]++; - } - return bins; -} diff --git a/lab34/histogram.h b/lab34/histogram.h deleted file mode 100644 index 71ce8fa..0000000 --- a/lab34/histogram.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include - -std::vector -make_histogram(const std::vector& numbers, size_t bin_count); - diff --git a/lab34/lab34.cbp b/lab34/lab34.cbp deleted file mode 100644 index 5cfcdaa..0000000 --- a/lab34/lab34.cbp +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - diff --git a/lab34/main.cpp b/lab34/main.cpp deleted file mode 100644 index fd75335..0000000 --- a/lab34/main.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include "histogram.h" -#include "text.h" -#include "svg.h" - -using namespace std; - -struct Input { - vector numbers; - size_t bin_count{}; -}; - -Input -input_data(){ - size_t number_count; - cin >> number_count; - Input in; - in.numbers.resize(number_count); - vector numbers(number_count); - for (size_t i = 0; i < number_count; i++) { - cin >> in.numbers[i]; - } - cin >> in.bin_count; - return in; -} - - -int -main() { - auto in = input_data(); - auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins); - return 0; -} diff --git a/lab34/svg.cpp b/lab34/svg.cpp deleted file mode 100644 index c8cd4e1..0000000 --- a/lab34/svg.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "svg.h" -#include -#include - -using namespace std; - -void -svg_begin(double width, double height) { - cout << "\n"; - cout << "\n"; -} - -void -svg_end() { - cout << "\n"; -} - -void -svg_text(double left, double baseline, string text) { - cout << "" << text << ""; -} - -void -svg_rect(double x, double y, double width, double height, - string stroke = "black", string fill = "orange"){ - cout << ""; -} - - -void -show_histogram_svg(const vector& bins) { - const auto IMAGE_WIDTH = 400; - const auto IMAGE_HEIGHT = 300; - const auto TEXT_LEFT = 20; - const auto TEXT_BASELINE = 20; - const auto TEXT_WIDTH = 50; - const auto BIN_HEIGHT = 30; - const auto BLOCK_WIDTH = 10; - svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); - double top = 0; - double maxbin = bins[0]; - for (size_t bin : bins) { - if (maxbin < bin){ - maxbin = bin; - } - } - for (size_t bin : bins) { - double bin_width = BLOCK_WIDTH * bin; - if ((IMAGE_WIDTH - TEXT_WIDTH) < (bin * BLOCK_WIDTH)){ - bin_width = (IMAGE_WIDTH - TEXT_WIDTH) * ( bin / maxbin ); - } - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); - top += BIN_HEIGHT; - } - svg_end(); -} diff --git a/lab34/svg.h b/lab34/svg.h deleted file mode 100644 index 5e3353c..0000000 --- a/lab34/svg.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include - -void -show_histogram_svg(const std::vector& bins); diff --git a/lab34/text.cpp b/lab34/text.cpp deleted file mode 100644 index 1e1fdca..0000000 --- a/lab34/text.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "text.h" -#include -#include - -using namespace std; - -const size_t SCREEN_WIDTH = 80; -const size_t MAX_LENGTH = SCREEN_WIDTH - 3 - 1; - -void -show_histogram_text(vector bins, size_t bin_count ){ - auto max_count = bins[0]; - for (auto x : bins) { - if (x > max_count) { - max_count = x; - } - } - for (size_t i = 0; i < bin_count; i++) { - size_t j = 100; - while (bins[i] < j) { - cout << " "; - j /= 10; - } - cout << bins[i] << "|"; - if (max_count > MAX_LENGTH) { - auto count = bins[i]; - size_t height = MAX_LENGTH * (static_cast(count) / max_count); - j = 0; - while (j < height) { - cout << "*"; - j++; - } - } - else { - j = 0; - while (j < bins[i]) { - cout << "*"; - j++; - } - } - cout << endl; - } -} diff --git a/lab34/text.h b/lab34/text.h deleted file mode 100644 index 52f62a7..0000000 --- a/lab34/text.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include - -void -show_histogram_text(std::vector bins, size_t bin_count );