diff --git a/lab01.cbp b/lab01.cbp
index d541ad7..d4ce774 100644
--- a/lab01.cbp
+++ b/lab01.cbp
@@ -32,7 +32,13 @@
+
+
+
+
+
+
diff --git a/main.cpp b/main.cpp
index 76f7f98..269c145 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,10 +1,11 @@
#include
#include
+#include "histogram.h"
+#include "text.h"
+#include "histogram_internal.h"
+#include "svg.h"
using namespace std;
-
-const size_t SCREEN_WIDTH = 80;
-const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
struct Input {
vector numbers;
size_t bin_count{};
@@ -28,102 +29,11 @@ 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, double bin_count){
- double min, max;
- find_minmax(numbers, min, max);
- double bin_size = (max - min) / bin_count; //размер корзины
- vector binss(bin_count);
- size_t number_count = numbers.size();
- //заполнение массива бинс
- for (size_t i = 0; i < number_count; i++)
- {
- bool found = false;
- for (size_t 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))
- {
- binss[j]++;
- found = true;
- }
- }
- if (!found)
- {
- binss[bin_count - 1]++;
- }
- }
- return binss;
-}
-
-void
-show_histogram_text(const vector& bins, double bin_count){
-double max_count;
- //максимадбное колво чисел в корзине среди всех корзин
- max_count = bins[0];
- for (size_t i = 0; i < bin_count; i++)
- {
- if (bins[i] > max_count)
- {
- max_count = bins[i];
- }
- }
-
- //вывод с выравниванием и масштабированием
- for (size_t i = 0; i < bin_count; i++)
- {
- size_t height;
- if (max_count <= MAX_ASTERISK)
- {
- height = bins[i];
- }
- else
- {
- height = MAX_ASTERISK * (static_cast(bins[i]) / max_count);
- }
-
- if (bins[i] < 10){
- cout << " ";
- }
- if (bins[i] < 100){
- cout << " ";
- }
- cout << bins[i] << "|";
- for (size_t j = 0; j < height; j++)
- {
- cout << "*";
- }
- cout << "\n";
- }
- }
-
-
-
-
-
int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
- show_histogram_text(bins, in.bin_count);
+ show_histogram_svg(bins, in.bin_count);
return 0;
}