From 65e569dbdbc299c08a19c4e1965599cede942ea1 Mon Sep 17 00:00:00 2001 From: "Alice (TimoshenkoAA)" Date: Sat, 27 Apr 2024 21:44:25 +0300 Subject: [PATCH] =?UTF-8?q?svg:=20=D0=BF=D1=83=D1=81=D1=82=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab01/doctest.h | 4 ++-- lab01/main.cpp | 63 ++++--------------------------------------------- lab01/svg.cpp | 24 +++++++++++++++++++ lab01/svg.h | 4 ++++ lab01/text.cpp | 2 +- 5 files changed, 35 insertions(+), 62 deletions(-) create mode 100644 lab01/svg.cpp create mode 100644 lab01/svg.h diff --git a/lab01/doctest.h b/lab01/doctest.h index 50474cc..0777727 100644 --- a/lab01/doctest.h +++ b/lab01/doctest.h @@ -1,4 +1,4 @@ -====================================================================== lgtm [cpp/missing-header-guard] +//====================================================================== lgtm [cpp/missing-header-guard] // == DO NOT MODIFY THIS FILE BY HAND - IT IS AUTO GENERATED BY CMAKE! == // ====================================================================== // @@ -5724,7 +5724,7 @@ namespace { std::tm timeInfo; #ifdef DOCTEST_PLATFORM_WINDOWS - gmtime_s(&timeInfo, &rawtime); +// gmtime_s(&timeInfo, &rawtime); #else // DOCTEST_PLATFORM_WINDOWS gmtime_r(&rawtime, &timeInfo); #endif // DOCTEST_PLATFORM_WINDOWS diff --git a/lab01/main.cpp b/lab01/main.cpp index f0ecd3a..905f156 100644 --- a/lab01/main.cpp +++ b/lab01/main.cpp @@ -1,6 +1,9 @@ #include #include #include +#include "histogram.h" +#include "text.h" +#include "svg.h" using namespace std; struct Input { vector numbers; @@ -26,65 +29,7 @@ input_data() { return in; } -void -find_minmax(const vector& numbers, double& min, double& max) { - min = numbers[0]; - max = numbers[0]; - for (double x : numbers) { - if (x < min) { - min = x; - } - else if (x > max) { - max = x; - } - } -} - -vector -make_histogram(const vector& numbers, size_t bin_count){ - vector bins (bin_count); - double min = 0, max = 0; - find_minmax(numbers, min, max); - - double bin_size = (max - min) / bin_count; - for (int i = 0; i < numbers.size(); i++) { - bool found = false; - for (int 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,size_t MAX_ASTERISK, size_t bin_count){ - double max_count = bins[0]; - for (double x: bins){ - if (x > max_count) { - max_count = x; - } - } - - for (int i = 0; i < bin_count; i++){ - double count = bins[i]; - size_t height = MAX_ASTERISK * (static_cast(count) / max_count); - string line (height , '*'); - if (bins[i]<100) - {cout << ' ';} - if (bins[i]<10) - {cout << ' ';} - cout << bins[i] << "|" << line << endl; - } -} int main() { const size_t SCREEN_WIDTH = 80; @@ -92,6 +37,6 @@ int main() auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins, MAX_ASTERISK, in.bin_count); + show_histogram_svg(bins); return 0; } diff --git a/lab01/svg.cpp b/lab01/svg.cpp new file mode 100644 index 0000000..1b08098 --- /dev/null +++ b/lab01/svg.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +void +svg_begin(double width, double height) { + cout << "\n"; + cout << "\n"; +} + +void +svg_end() { + cout << "\n"; +} + +void +show_histogram_svg(const vector & bins) { + svg_begin(400, 300); + svg_end(); +} diff --git a/lab01/svg.h b/lab01/svg.h new file mode 100644 index 0000000..35aeda2 --- /dev/null +++ b/lab01/svg.h @@ -0,0 +1,4 @@ +#pragma once + +void +show_histogram_svg(const std::vector& bins); diff --git a/lab01/text.cpp b/lab01/text.cpp index 5272b36..f7f67bf 100644 --- a/lab01/text.cpp +++ b/lab01/text.cpp @@ -4,7 +4,7 @@ using namespace std; void -show_histogram_text (const vector& bins,size_t MAX_ASTERISK, size_t bin_count){ +show_histogram_text (const vector& bins, size_t MAX_ASTERISK, size_t bin_count){ double max_count = bins[0]; for (double x: bins){ if (x > max_count) {