commit a1f92af2271da390f8965d2c4e0c5db4b225b7cc Author: GaidaiAS Date: Wed Apr 30 17:13:25 2025 +0300 code: начальный код 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.actual.txt b/bin/Debug/02-alignment.actual.txt new file mode 100644 index 0000000..e69de29 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/03-scaling.actual.txt b/bin/Debug/03-scaling.actual.txt new file mode 100644 index 0000000..693ba1a --- /dev/null +++ b/bin/Debug/03-scaling.actual.txt @@ -0,0 +1,3 @@ + 9|****** + 33|************************* +100|**************************************************************************** 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/1.bat.txt b/bin/Debug/1.bat.txt new file mode 100644 index 0000000..e69de29 diff --git a/bin/Debug/NULL b/bin/Debug/NULL new file mode 100644 index 0000000..a87e12a --- /dev/null +++ b/bin/Debug/NULL @@ -0,0 +1 @@ +Enter number count:numbers[1]=numbers[2]=numbers[3]=numbers[4]=numbers[5]=numbers[6]=numbers[7]=numbers[8]=numbers[9]=numbers[10]=numbers[11]=numbers[12]=numbers[13]=numbers[14]=numbers[15]=numbers[16]=numbers[17]=numbers[18]=numbers[19]=numbers[20]=numbers[21]=numbers[22]=numbers[23]=numbers[24]=numbers[25]=numbers[26]=numbers[27]=numbers[28]=numbers[29]=numbers[30]=numbers[31]=numbers[32]=numbers[33]=numbers[34]=numbers[35]=numbers[36]=numbers[37]=numbers[38]=numbers[39]=numbers[40]=numbers[41]=numbers[42]=numbers[43]=numbers[44]=numbers[45]=numbers[46]=numbers[47]=numbers[48]=numbers[49]=numbers[50]=numbers[51]=numbers[52]=numbers[53]=numbers[54]=numbers[55]=numbers[56]=numbers[57]=numbers[58]=numbers[59]=numbers[60]=numbers[61]=numbers[62]=numbers[63]=numbers[64]=numbers[65]=numbers[66]=numbers[67]=numbers[68]=numbers[69]=numbers[70]=numbers[71]=numbers[72]=numbers[73]=numbers[74]=numbers[75]=numbers[76]=numbers[77]=numbers[78]=numbers[79]=numbers[80]=numbers[81]=numbers[82]=numbers[83]=numbers[84]=numbers[85]=numbers[86]=numbers[87]=numbers[88]=numbers[89]=numbers[90]=numbers[91]=numbers[92]=numbers[93]=numbers[94]=numbers[95]=numbers[96]=numbers[97]=numbers[98]=numbers[99]=numbers[100]=numbers[101]=numbers[102]=numbers[103]=numbers[104]=numbers[105]=numbers[106]=numbers[107]=numbers[108]=numbers[109]=numbers[110]=numbers[111]=numbers[112]=numbers[113]=numbers[114]=numbers[115]=numbers[116]=numbers[117]=numbers[118]=numbers[119]=numbers[120]=numbers[121]=numbers[122]=numbers[123]=numbers[124]=numbers[125]=numbers[126]=numbers[127]=numbers[128]=numbers[129]=numbers[130]=numbers[131]=numbers[132]=numbers[133]=numbers[134]=numbers[135]=numbers[136]=numbers[137]=numbers[138]=numbers[139]=numbers[140]=numbers[141]=numbers[142]=Enter bin count: \ No newline at end of file diff --git a/bin/Debug/lab01.exe b/bin/Debug/lab01.exe new file mode 100644 index 0000000..d801e2a Binary files /dev/null and b/bin/Debug/lab01.exe differ diff --git a/bin/Debug/libgcc_s_seh-1.dll b/bin/Debug/libgcc_s_seh-1.dll new file mode 100644 index 0000000..66b1a55 Binary files /dev/null and b/bin/Debug/libgcc_s_seh-1.dll differ diff --git a/bin/Debug/libstdc++-6.dll b/bin/Debug/libstdc++-6.dll new file mode 100644 index 0000000..18dc683 Binary files /dev/null and b/bin/Debug/libstdc++-6.dll differ diff --git a/bin/Debug/libwinpthread-1.dll b/bin/Debug/libwinpthread-1.dll new file mode 100644 index 0000000..d0d1223 Binary files /dev/null and b/bin/Debug/libwinpthread-1.dll differ diff --git a/bin/Debug/mm.txt b/bin/Debug/mm.txt new file mode 100644 index 0000000..e69de29 diff --git a/bin/Debug/start1.bat b/bin/Debug/start1.bat new file mode 100644 index 0000000..15f6987 --- /dev/null +++ b/bin/Debug/start1.bat @@ -0,0 +1,3 @@ +lab01.exe< 01-example.input.txt > 01-example.actual.txt 2>NUL +fc /N 03-scaling.actual.txt 03-scaling.expected.txt +pause \ No newline at end of file diff --git a/bin/Debug/start2.bat b/bin/Debug/start2.bat new file mode 100644 index 0000000..f325e48 --- /dev/null +++ b/bin/Debug/start2.bat @@ -0,0 +1,3 @@ +Lab1.exe < 02-alignment.input.txt > 02-alignment.actual.txt 2>NUL +fc /N 02-alignment.actual.txt 02-alignment.expected.txt +pause \ No newline at end of file diff --git a/bin/Debug/start3.bat b/bin/Debug/start3.bat new file mode 100644 index 0000000..dbbed8d --- /dev/null +++ b/bin/Debug/start3.bat @@ -0,0 +1,3 @@ +lab01.exe< 03-scaling.input.txt > 03-scaling.actual.txt 2>NULL +fc /N 03-scaling.actual.txt 03-scaling.expected.txt +pause \ No newline at end of file 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..282cd9f --- /dev/null +++ b/lab01.depend @@ -0,0 +1,8 @@ +# depslib dependency file v1.0 +1741341308 source:c:\mpei\programming\c++ 2sem\lab01\main.cpp + + + + + + diff --git a/lab01.exe.depend b/lab01.exe.depend new file mode 100644 index 0000000..a43fe34 --- /dev/null +++ b/lab01.exe.depend @@ -0,0 +1,5 @@ +# depslib dependency file v1.0 +1741281318 source:c:\mpei\programming\c++ 2sem\lab01\main.cpp + + + diff --git a/lab01.exe.layout b/lab01.exe.layout new file mode 100644 index 0000000..a261d0f --- /dev/null +++ b/lab01.exe.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/lab01.layout b/lab01.layout new file mode 100644 index 0000000..ac99591 --- /dev/null +++ b/lab01.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a7864a0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +using namespace std; + +int main() { + srand(42); + + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + size_t number_count; + cerr << "Enter number count: "; + cin >> number_count; + + string choice; + cerr << "Generate numbers?: "; + cin >> choice; + + vector numbers(number_count); + if (choice == "yes") { + for (size_t i = 0; i < number_count; i++) { + numbers[i] = 0; + for (int j = 0; j < 12; j++) { + numbers[i] += rand(); + } + } + } + else + { + 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; + + vector bins(bin_count, 0); + + double min = numbers[0]; + double max = numbers[0]; + for (double x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } + } + + 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]++; + } + } + + size_t max_bin_count = 0; + for (size_t bin : bins) { + if (bin > max_bin_count) { + max_bin_count = bin; + } + } + + for (size_t i = 0; i < bin_count; i++) { + cout << bins[i] << " |"; + size_t height = (max_bin_count <= MAX_ASTERISK) ? bins[i] : static_cast(MAX_ASTERISK * (static_cast(bins[i]) / max_bin_count)); + for (size_t j = 0; j < height; j++) { + cout << "*"; + } + cout << endl; + } + + return 0; +} diff --git a/obj/Debug/main.o b/obj/Debug/main.o new file mode 100644 index 0000000..1be6c46 Binary files /dev/null and b/obj/Debug/main.o differ