diff --git a/Lab01.cbp b/Lab01.cbp
index d25c7da..aa7d216 100644
--- a/Lab01.cbp
+++ b/Lab01.cbp
@@ -34,6 +34,8 @@
+
+
diff --git a/main.cpp b/main.cpp
index 4e8bb0d..8883021 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,7 @@
#include
#include
#include "histogram.h"
+#include "text.h"
using namespace std;
struct Input
{
@@ -25,63 +26,6 @@ input_data()
}
return in;
}
-void
-show_histogram_text(const vector &bins)
-{
- const size_t SCREEN_WIDTH = 80;
- const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
- int max_count = bins[0];
- for (size_t i = 0; i < bins.size(); i++)
- {
- if (bins[i] > max_count)
- {
- max_count = bins[i];
- }
- }
- if (max_count > MAX_ASTERISK)
- {
- for (int i = 0; i < bins.size(); i++)
- {
- size_t height = MAX_ASTERISK * (static_cast(bins[i]) / max_count);
- if (bins[i] < 100)
- {
- cout << " ";
- if (bins[i] < 10)
- {
- cout << " ";
- }
- }
- cout << bins[i] << "|";
- for (size_t j = 0; j < height; j++)
- {
- cout << "*";
- }
- cout << endl;
- }
- }
-
- else
- {
- for (int i = 0; i < bins.size(); i++)
- {
- if (bins[i] < 100)
- {
- cout << " ";
- if (bins [i] < 10)
- {
- cout << " ";
- }
- }
- cout << bins[i] << "|";
- for (int j = 0; j < bins[i]; j++)
- {
- cout << "*";
- }
- cout << endl;
- }
- }
-}
-
int
main()
{
diff --git a/text.cpp b/text.cpp
new file mode 100644
index 0000000..f272c99
--- /dev/null
+++ b/text.cpp
@@ -0,0 +1,61 @@
+#include
+#include
+#include "text.h"
+
+const std::size_t SCREEN_WIDTH = 80;
+const std::size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
+
+void
+show_histogram_text(const std::vector &bins)
+{
+ std::size_t max_count = bins[0];
+ for (std::size_t i = 0; i < bins.size(); i++)
+ {
+ if (bins[i] > max_count)
+ {
+ max_count = bins[i];
+ }
+ }
+ if (max_count > MAX_ASTERISK)
+ {
+ for (std::size_t i = 0; i < bins.size(); i++)
+ {
+ std::size_t height = MAX_ASTERISK * (static_cast(bins[i]) / max_count);
+ if (bins[i] < 100)
+ {
+ std::cout << " ";
+ if (bins[i] < 10)
+ {
+ std::cout << " ";
+ }
+ }
+ std::cout << bins[i] << "|";
+ for (std::size_t j = 0; j < height; j++)
+ {
+ std::cout << "*";
+ }
+ std::cout << std::endl;
+ }
+ }
+
+ else
+ {
+ for (int i = 0; i < bins.size(); i++)
+ {
+ if (bins[i] < 100)
+ {
+ std::cout << " ";
+ if (bins [i] < 10)
+ {
+ std::cout << " ";
+ }
+ }
+ std::cout << bins[i] << "|";
+ for (int j = 0; j < bins[i]; j++)
+ {
+ std::cout << "*";
+ }
+ std::cout << std::endl;
+ }
+ }
+}
diff --git a/text.h b/text.h
new file mode 100644
index 0000000..86bd41e
--- /dev/null
+++ b/text.h
@@ -0,0 +1,8 @@
+#ifndef TEXT_H_INCLUDED
+#define TEXT_H_INCLUDED
+
+#include
+
+void show_histogram_text(const std::vector &bins);
+
+#endif // TEXT_H_INCLUDED