From 2e6d5b708dad50535e357924fa62d397eb23fa8d Mon Sep 17 00:00:00 2001 From: BiriukovaAlS Date: Sat, 3 Jun 2023 19:20:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D0=B4=D0=B8=D0=B2=D0=B8=D0=B4?= =?UTF-8?q?=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 57 +++++++++++++++++++++++++++++++++++ histogram.h | 7 +++++ lab3344.cbp | 40 +++++++++++++++++++++++++ main.cpp | 46 +++++++++++++++++++++++++++++ svg.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ svg.h | 7 +++++ text.cpp | 41 ++++++++++++++++++++++++++ text.h | 6 ++++ 8 files changed, 286 insertions(+) create mode 100644 histogram.cpp create mode 100644 histogram.h create mode 100644 lab3344.cbp create mode 100644 main.cpp create mode 100644 svg.cpp create mode 100644 svg.h create mode 100644 text.cpp create mode 100644 text.h diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..eb109b9 --- /dev/null +++ b/histogram.cpp @@ -0,0 +1,57 @@ +#include "histogram.h" +#include +#include "histogram_internal.h" + +using namespace std; +bool find_minmax(const vector& numbers, double& minp, double& maxp) +{ + if (numbers.size() == 0) + return false; + + minp = numbers[0]; + for (auto i = 0; imaxp) + { + maxp = numbers[i]; + } + } + return true; +} + +vector make_histogram (const vector& numbers, size_t kol_kor) +{ + vectorB(kol_kor); + size_t max_count; + double maxp, minp; + find_minmax(numbers, minp, maxp); + double step = (maxp-minp)/(kol_kor); + + for (size_t i=0; i=(minp+j*step))&&(numbers[i]<(minp+(j+1)*step))) + { + B[j]++; + break; + } + } + } + + for (size_t i=0; i +std::vector +make_histogram(const std::vector& numbers, size_t kol_kor); + +#endif // HISTOGRAM_H_INCLUDED diff --git a/lab3344.cbp b/lab3344.cbp new file mode 100644 index 0000000..f10a211 --- /dev/null +++ b/lab3344.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..0b5bd0e --- /dev/null +++ b/main.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include "histogram.h" +#include "text.h" +#include "svg.h" + +using namespace std; + +struct Input +{ + vectornumbers; + size_t kol_kor{}; + size_t number_count; +}; + +Input +input_data() +{ + Input in; + + cerr<<"Marks: "; + cin>>in.number_count; + + + in.numbers.resize(in.number_count); + for (size_t i=0; i>in.kol_kor; + return in; +} + +int main() +{ + size_t number_count; + auto in = input_data(); + auto B = make_histogram(in.numbers, in.kol_kor); + show_histogram_svg(B, in.number_count); + + return 0; +} diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..cedbca0 --- /dev/null +++ b/svg.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include +#include "svg.h" +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, string fill) +{ + cout << ""; + +} + +void +show_histogram_svg(const vector& B, size_t& number_count) +{ + auto IMAGE_WIDTH=0; + const auto BLOCK_WIDTH = 10; + cerr << "Enter IMAGE_WIDTH:"; + cin >> IMAGE_WIDTH; + + while (IMAGE_WIDTH<70 || IMAGE_WIDTH>800 || IMAGE_WIDTH<(number_count/3.0*BLOCK_WIDTH)) + { + cout<<"Error, incorrect IMAGE_WIDTH, please, re-enter\n"; + cerr << "Enter IMAGE_WIDTH:"; + cin >> IMAGE_WIDTH; + } + + 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 MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH; + + svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); + + double top = 0; + double max_count = B[0]; + for (size_t i = 0; i < B.size(); i++) + { + if (max_count& B, size_t &number_count); + +#endif // SVG_H_INCLUDED diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..fb065ee --- /dev/null +++ b/text.cpp @@ -0,0 +1,41 @@ +#include "text.h" +#include +#include + +using namespace std; +void show_histogram_text(vectorB, size_t kol_kor) +{ + + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + int max_count, count,j, height; + for (size_t i=0; i MAX_ASTERISK) + { + count = B[i]; + height = MAX_ASTERISK * (static_cast(count) / max_count); + } + + else + { + height = B[i]; + } + + for (j = 0; j < height; j++) + { + cout << "*"; + } + cout << endl; + } + return; +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..90e5f72 --- /dev/null +++ b/text.h @@ -0,0 +1,6 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED +#include +void show_histogram_text(std::vectorB, size_t kol_kor, size_t& IMAGE_WIDTH); + +#endif // TEXT_H_INCLUDED