From fc0813208150a203e4cb8632c11593194efbdc6b Mon Sep 17 00:00:00 2001 From: KhatyukhinYS Date: Mon, 22 Apr 2024 12:17:43 +0300 Subject: [PATCH] code: last --- main.cpp | 14 +++++++++++--- marks.txt | 3 +++ svg.cpp | 44 +++++++++++++++++++------------------------- svg.h | 4 ++-- text.cpp | 31 ++++++++++++++++--------------- text.h | 2 +- 6 files changed, 52 insertions(+), 46 deletions(-) create mode 100644 marks.txt diff --git a/main.cpp b/main.cpp index e929184..12c0c1d 100644 --- a/main.cpp +++ b/main.cpp @@ -6,14 +6,14 @@ using namespace std; struct Input { std::vector numbers; - size_t bin_count{}; size_t number_count{}; + size_t bin_count{}; }; Input input_data() { size_t number_count; - cin >> number_count; Input in; + cin >> number_count; in.numbers.resize(number_count); for (size_t i = 0; i < number_count; i++) { cin >> in.numbers[i]; @@ -26,6 +26,14 @@ int main() { auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins); + //show_histogram_text(bins,in.bin_count,in.numbers); + auto max_count=bins[0]; + for(size_t x : bins){ + if (x > max_count) + { + max_count=x; + } + } + show_histogram_svg(bins, max_count); return 0; } diff --git a/marks.txt b/marks.txt new file mode 100644 index 0000000..2cdb9aa --- /dev/null +++ b/marks.txt @@ -0,0 +1,3 @@ +10 +3 3 4 4 4 4 4 5 5 5 +3 diff --git a/svg.cpp b/svg.cpp index 898dc45..72de81b 100644 --- a/svg.cpp +++ b/svg.cpp @@ -5,50 +5,44 @@ using namespace std; void svg_begin(double width, double height) { - cout << "\n"; - cout << "\n"; -} -void -svg_text(double left, double baseline, string text) { - cout << "anything you want"; + std::cout << "\n"; + std::cout << "\n"; } + void -svg_rect(double x, double y, double width, double height){ - cout << "\n"; +svg_text(double left, double baseline, std::string text) { + std::cout << ""<< text <<""; } -void svg_rect(double x, double y, double width, double height, - string stroke = "black", string fill = "black"){ - cout << "\n"; +void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fil = "black"){ + std::cout<< ""; } void svg_end() { - cout << "\n"; + std::cout << "\n"; } void -show_histogram_svg(const vector bins) { +show_histogram_svg(std::vector bins,size_t max_count) { 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(400, 300); -// svg_rect(50, 0,bins[0] * 10, 30); - svg_text(20, 20, to_string(bins[0])); - svg_end(); + const auto BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH)/max_count; + + svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); double top = 0; for (size_t bin : bins) { const double bin_width = BLOCK_WIDTH * bin; - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); -// svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); top += BIN_HEIGHT; } - svg_rect(0, 0, 100, 200, "blue", "#aaffaa"); + svg_end(); } diff --git a/svg.h b/svg.h index 1242c0e..c9e4a8e 100644 --- a/svg.h +++ b/svg.h @@ -2,9 +2,9 @@ #define SVG_H_INCLUDED #include #include - +using namespace std; void -show_histogram_svg(std::vector bins); +show_histogram_svg(std::vector bins,size_t max_count); #endif // SVG_H_INCLUDED diff --git a/text.cpp b/text.cpp index 3ce093a..4f5f3a8 100644 --- a/text.cpp +++ b/text.cpp @@ -1,30 +1,31 @@ #include #include +#include #include "text.h" using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; -void show_histogram_text(const std::vector bins, size_t bin_count) +void show_histogram_text(const std::vector bins, size_t bin_count, const std::vector numbers) { - size_t max_count = bins[0]; - for(size_t x : bins) - { - if(x > max_count) - { - max_count = x; - } - } - for(size_t i = 0;i MAX_ASTERISK) - height = MAX_ASTERISK * (static_cast(bins[i]) / max_count); - for(size_t j = 0;j void -show_histogram_text(const std::vector bins, size_t bin_count); +show_histogram_text(const std::vector bins, size_t bin_count,const std::vector numbers); #endif // TEXT_H_INCLUDED