diff --git a/bin/Debug/01-example.actual.txt b/bin/Debug/01-example.actual.txt new file mode 100644 index 0000000..b0a2599 --- /dev/null +++ b/bin/Debug/01-example.actual.txt @@ -0,0 +1,3 @@ + 2|** + 5|***** + 3|*** diff --git a/bin/Debug/01-example.expected.txt b/bin/Debug/01-example.expected.txt new file mode 100644 index 0000000..b0a2599 --- /dev/null +++ b/bin/Debug/01-example.expected.txt @@ -0,0 +1,3 @@ + 2|** + 5|***** + 3|*** diff --git a/bin/Debug/01-example.input.txt b/bin/Debug/01-example.input.txt new file mode 100644 index 0000000..6ef9fde --- /dev/null +++ b/bin/Debug/01-example.input.txt @@ -0,0 +1,3 @@ +10 +4 4 3 5 3 4 5 5 4 4 +3 diff --git a/bin/Debug/02-alignment.expected.txt b/bin/Debug/02-alignment.expected.txt new file mode 100644 index 0000000..094c19f --- /dev/null +++ b/bin/Debug/02-alignment.expected.txt @@ -0,0 +1,3 @@ + 9|********* + 33|********************************* +100|**************************************************************************************************** diff --git a/bin/Debug/02-alignment.input.txt b/bin/Debug/02-alignment.input.txt new file mode 100644 index 0000000..2539400 --- /dev/null +++ b/bin/Debug/02-alignment.input.txt @@ -0,0 +1,5 @@ +142 +1 1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 +3 diff --git a/bin/Debug/lab01.exe b/bin/Debug/lab01.exe new file mode 100644 index 0000000..eeaf532 Binary files /dev/null and b/bin/Debug/lab01.exe differ diff --git a/bin/Debug/marks.svg b/bin/Debug/marks.svg new file mode 100644 index 0000000..4182ab9 --- /dev/null +++ b/bin/Debug/marks.svg @@ -0,0 +1,3 @@ + + +253 diff --git a/bin/Debug/marks.txt b/bin/Debug/marks.txt new file mode 100644 index 0000000..2cdb9aa --- /dev/null +++ b/bin/Debug/marks.txt @@ -0,0 +1,3 @@ +10 +3 3 4 4 4 4 4 5 5 5 +3 diff --git a/bin/Debug/test1.bat b/bin/Debug/test1.bat new file mode 100644 index 0000000..bfa37f2 --- /dev/null +++ b/bin/Debug/test1.bat @@ -0,0 +1,2 @@ +lab01.exe < 01-example.input.txt > 01-example.actual.txt 2>NUL +fc /N 01-example.actual.txt 01-example.expected.txt || pause \ No newline at end of file diff --git a/bin/Debug/test2.bat b/bin/Debug/test2.bat new file mode 100644 index 0000000..224c184 --- /dev/null +++ b/bin/Debug/test2.bat @@ -0,0 +1,2 @@ +lab01.exe < 02-alignment.input.txt > 01-example.actual.txt 2>NUL +fc /N 01-example.actual.txt 02-alignment.expected.txt || pause \ No newline at end of file diff --git a/bin/Debug/unittest.exe b/bin/Debug/unittest.exe new file mode 100644 index 0000000..0343f43 Binary files /dev/null and b/bin/Debug/unittest.exe differ diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..932942b --- /dev/null +++ b/histogram.cpp @@ -0,0 +1,58 @@ +#include "histogram.h" +#include "histogram_internal.h" + +using namespace std; + +void +find_minmax(const vector& numbers, double& min, double& max) +{ + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) + { + if (xmax) + { + max=x; + } + } +} + +vector +make_histogram(const vector& numbers, size_t bin_count) +{ + vector bins(bin_count); + double min, max; + find_minmax(numbers, min, max); + + double bin_size = (max - min) / bin_count; + + size_t max_count = 0; + + for (size_t i = 0; i < numbers.size(); 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)) + { + bins[j]++; + if (bins[j] > max_count) + { + max_count = bins[j]; + } + found = true; + } + } + if (!found) + { + bins[bin_count - 1]++; + } + } + return bins; +} diff --git a/histogram.h b/histogram.h new file mode 100644 index 0000000..0d8dc8c --- /dev/null +++ b/histogram.h @@ -0,0 +1,9 @@ +#ifndef HISTOGRAM_H_INCLUDED +#define HISTOGRAM_H_INCLUDED + +#include + +std::vector +make_histogram(const std::vector& numbers, size_t bin_count); + +#endif // HISTOGRAM_H_INCLUDED diff --git a/histogram_internal.h b/histogram_internal.h new file mode 100644 index 0000000..3a2e060 --- /dev/null +++ b/histogram_internal.h @@ -0,0 +1,9 @@ +#ifndef HISTOGRAM_INTERNAL_H_INCLUDED +#define HISTOGRAM_INTERNAL_H_INCLUDED + +#include + +void +find_minmax(const std::vector& numbers, double& min, double& max); + +#endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/lab01 b/lab01 new file mode 100644 index 0000000..e69de29 diff --git a/lab01.cbp b/lab01.cbp index e4dd928..61d707f 100644 --- a/lab01.cbp +++ b/lab01.cbp @@ -40,6 +40,10 @@