commit 095673b78a554c93d235787906f1c3e3a7773440 Author: IvanovArtAl Date: Sat Jul 5 12:50:28 2025 +0300 lab01 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..693ba1a --- /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/03-scaling.expected.txt b/bin/Debug/03-scaling.expected.txt new file mode 100644 index 0000000..693ba1a --- /dev/null +++ b/bin/Debug/03-scaling.expected.txt @@ -0,0 +1,3 @@ + 9|****** + 33|************************* +100|**************************************************************************** diff --git a/bin/Debug/03-scaling.input.txt b/bin/Debug/03-scaling.input.txt new file mode 100644 index 0000000..2539400 --- /dev/null +++ b/bin/Debug/03-scaling.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/bat1.bat b/bin/Debug/bat1.bat new file mode 100644 index 0000000..1d1a379 --- /dev/null +++ b/bin/Debug/bat1.bat @@ -0,0 +1,2 @@ +lab01.exe < 01-example.input.txt > 01-example.actual.txt 2 +fc /N 01-example.actual.txt 01-example.expected.txt \ No newline at end of file diff --git a/bin/Debug/bat2.bat b/bin/Debug/bat2.bat new file mode 100644 index 0000000..df50ba1 --- /dev/null +++ b/bin/Debug/bat2.bat @@ -0,0 +1,2 @@ +lab01.exe < 02-alignment.input.txt > 02-alignment.expected.txt +fc /N 02-alignment.input.txt 02-alignment.expected.txt \ No newline at end of file diff --git a/bin/Debug/bat3.bat b/bin/Debug/bat3.bat new file mode 100644 index 0000000..84a1b38 --- /dev/null +++ b/bin/Debug/bat3.bat @@ -0,0 +1,2 @@ +lab01.exe < 03-scaling.input.txt > 03-scaling.expected.txt +fc /N 03-scaling.input.txt 03-scaling.expected.txt \ No newline at end of file diff --git a/bin/Debug/lab01 b/bin/Debug/lab01 new file mode 100644 index 0000000..e69de29 diff --git a/bin/Debug/lab01.exe b/bin/Debug/lab01.exe new file mode 100644 index 0000000..1db7af6 Binary files /dev/null and b/bin/Debug/lab01.exe differ diff --git a/lab01.cbp b/lab01.cbp new file mode 100644 index 0000000..d541ad7 --- /dev/null +++ b/lab01.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/lab01.depend b/lab01.depend new file mode 100644 index 0000000..26edadf --- /dev/null +++ b/lab01.depend @@ -0,0 +1,5 @@ +# depslib dependency file v1.0 +1748860968 source:c:\users\ncnf\desktop\lab01\lab01\main.cpp + + + diff --git a/lab01.layout b/lab01.layout new file mode 100644 index 0000000..be93af1 --- /dev/null +++ b/lab01.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8a71327 --- /dev/null +++ b/main.cpp @@ -0,0 +1,95 @@ +#include +#include + +using namespace std; + +int main() +{ + size_t number_count; + cerr << "Enter number count: "; + cin >> number_count; + + vector numbers(number_count); + cerr << "Enter numbers: "; + for(size_t i = 0; i < number_count; i ++) + { + cin >> numbers[i]; + } + + size_t bin_count; + cerr << "Enter bin count: "; + cin >> bin_count; + + double min = numbers[0]; + double max = numbers[0]; + for(double number : numbers) + { + if(number < min) + { + min = number; + } + if(number > max) + { + max = number; + } + } + + vector bins(bin_count, 0); + double bin_size = (max - min) / bin_count; + 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)) + { + bins[j]++; + found = true; + } + } + if (!found) + { + bins[bin_count-1]++; + } + } + + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + + size_t max_bin = bins[0]; + for(size_t i = 0; i < bin_count; i++) + { + if(bins[i] > max_bin) + { + max_bin = bins[i]; + } + } + + for (size_t bin: bins) + { + size_t height = bin; + + if (max_bin > MAX_ASTERISK) + { + height = MAX_ASTERISK * (static_cast(bin) / max_bin); + } + + if (bin < 100) + { + cout << ' '; + } + if (bin < 10) + { + cout << ' '; + } + cout << bin << "|"; + for(size_t i = 0; i < height; i++) + { + cout << "*"; + } + cout << endl; + } + +} diff --git a/obj/Debug/main.o b/obj/Debug/main.o new file mode 100644 index 0000000..734eb78 Binary files /dev/null and b/obj/Debug/main.o differ