commit 5de8e3f61a8a82faecb8a861b702cc57b76fe759 Author: Hihoffff Date: Thu May 29 20:26:37 2025 +0300 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a079b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin +/obj \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b9e42df --- /dev/null +++ b/main.cpp @@ -0,0 +1,54 @@ +using namespace std; +#include "histogram.h" +#include "text.h" +#include "svg.h" + + + +struct Input { + std::vector numbers; + size_t bin_count{}; +}; + +Input input_data(istream& in, bool promt); + +int main() +{ + + Input in = input_data(cin); + std::vector bins = make_histogram(in.numbers, in.bin_count); + show_histogram_svg(bins); + + + return 0; +} +Input input_data(istream& in, bool promt) { + + Input input_struct; + size_t countOfNumbers; + if(promt){cerr << "Input your count of numbers:\n";} + + cin >> countOfNumbers; + + input_struct.numbers.resize(countOfNumbers); + if(promt){cerr << "Input numbers:\n";} + for (int i = 0; i < countOfNumbers; i++) { + if(promt){cerr << i << ":" << endl;} + cin >> input_struct.numbers[i]; + } + if(promt){ + cerr << endl; + cerr << "Input bin count:\n"; + } + + cin >> input_struct.bin_count; + + + + return input_struct; +} + + + + + diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..32bf8c5 --- /dev/null +++ b/svg.cpp @@ -0,0 +1,42 @@ +#include "svg.h" +#include "text.h" +void svg_begin(double width, double height) { + std::cout << "\n"; + std::cout << "\n"; +} + +void svg_end() { + std::cout << "\n"; +} + +void show_histogram_svg(const std::vector& bins) { + const auto IMAGE_WIDTH = 400; + const auto IMAGE_HEIGHT = 300; + const auto TEXT_LEFT = 20; + const auto TEXT_BASELINE = 20; + const auto BIN_HEIGHT = 30; + const auto TEXT_WIDTH = 50; + svg_begin(400, 300); + + size_t maxCount = maxBin(bins); + double top = 0; + for (size_t bin : bins) { + const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH) * (bin / double(maxCount)); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red","#006B3C"); + top += BIN_HEIGHT; + } + svg_end(); +} +void svg_text(double left, double baseline, std::string text) { + std::cout << "" << text<<""; +} +void svg_rect(double x, double y, double width, double height,std::string stroke="black", std::string fills="black"){ + std::cout << ""; +} + + diff --git a/svg.h b/svg.h new file mode 100644 index 0000000..c558da8 --- /dev/null +++ b/svg.h @@ -0,0 +1,12 @@ +#ifndef SVG_H_INCLUDED +#define SVG_H_INCLUDED + +#include +#include +void svg_begin(double width, double height); +void svg_end(); +void show_histogram_svg(const std::vector& bins); +void svg_text(double left, double baseline, std::string text); +void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills); + +#endif // SVG_H_INCLUDED diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..616d234 --- /dev/null +++ b/text.cpp @@ -0,0 +1,41 @@ +#include "text.h" + +void show_histogram_text(std::vector bins , size_t bin_count) { + size_t maxCount = maxBin(bins); + size_t count_stars; + for (size_t i = 0; i < bin_count; i++) { + + if (bins[i] < 100) { + std::cout << " "; + } + if (bins[i] < 10) { + std::cout << " "; + } + + std::cout << bins[i]; + std::cout << "|"; + + if (maxCount > MAX_ASTERISK) { + count_stars = MAX_ASTERISK * (static_cast(bins[i]) / maxCount); + } + else { + count_stars = bins[i]; + } + for (size_t i2 = 0; i2 < count_stars; i2++) { + std::cout << "*"; + } + std::cout << std::endl; + + + } +} + +const size_t maxBin(std::vector bins) { + size_t max = bins[0]; + for (int i = 1; i < bins.size(); i++) { + if (max < bins[i]) { + max = bins[i]; + } + } + return max; +} diff --git a/text.h b/text.h new file mode 100644 index 0000000..d3dd6b5 --- /dev/null +++ b/text.h @@ -0,0 +1,12 @@ +#ifndef TEXT_H_INCLUDED +#define TEXT_H_INCLUDED + + +#include +#include + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; +void show_histogram_text(std::vector bins , size_t bin_count); +const size_t maxBin(std::vector bins); +#endif // TEXT_H_INCLUDED