From b331617608ff6709c6a1e29066a756d304fb548f Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 12 Nov 2024 18:55:44 +0400 Subject: [PATCH] lab4 --- lr19/Project2/Project2.vcxproj | 135 ++++++++++++++ lr19/Project2/Project2.vcxproj.filters | 22 +++ lr19/Project2/Source.cpp | 64 +++++++ lr19/Project2/out.txt | 1 + lr19/lr19.sln | 31 ++++ lr19/lr19/Source.cpp | 234 +++++++++++++++++++++++++ lr19/lr19/lr19.vcxproj | 135 ++++++++++++++ lr19/lr19/lr19.vcxproj.filters | 22 +++ 8 files changed, 644 insertions(+) create mode 100644 lr19/Project2/Project2.vcxproj create mode 100644 lr19/Project2/Project2.vcxproj.filters create mode 100644 lr19/Project2/Source.cpp create mode 100644 lr19/Project2/out.txt create mode 100644 lr19/lr19.sln create mode 100644 lr19/lr19/Source.cpp create mode 100644 lr19/lr19/lr19.vcxproj create mode 100644 lr19/lr19/lr19.vcxproj.filters diff --git a/lr19/Project2/Project2.vcxproj b/lr19/Project2/Project2.vcxproj new file mode 100644 index 0000000..8eb7caa --- /dev/null +++ b/lr19/Project2/Project2.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {5bcdaf99-c3cf-4fca-ab91-8ac4b54a6e59} + Project2 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/lr19/Project2/Project2.vcxproj.filters b/lr19/Project2/Project2.vcxproj.filters new file mode 100644 index 0000000..ef66db6 --- /dev/null +++ b/lr19/Project2/Project2.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/lr19/Project2/Source.cpp b/lr19/Project2/Source.cpp new file mode 100644 index 0000000..8e23d01 --- /dev/null +++ b/lr19/Project2/Source.cpp @@ -0,0 +1,64 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include + + +int a[1000]; //. 1000 - +int n; // +void Load() { + // + FILE* fin = fopen("c:\\lab_19\\in1.txt", "rt"); + if (fin == NULL) { + printf(" \n"); + return; + } + + // + fscanf_s(fin, "%d", &n); + for (int i = 0; i < n; i++) { + fscanf_s(fin, "%d", &a[i]); + } + + // + fclose(fin); +} +void SaveResult() { + // + float sa = 0; + float s = 0; + for (int i = 0; i < n; i++) { + s += a[i]; + } + sa = s / n; + + // , + int m = 0; + for (int i = 0; i < n; i++) { + if (a[i] > sa) { + m++; + } + } + FILE* fout = fopen("c:\\lab_19\\out1.txt", "wt"); + if (fout == NULL) { + printf(" \n"); + return; + } + + // + fprintf(fout, "%d\n", m); + for (int i = 0; i < n; i++) { + if (a[i] > sa) { + fprintf(fout, "%d ", a[i]); + } + } + // + fclose(fout); +} +void main() { + SetConsoleCP(1251); + SetConsoleOutputCP(1251); + printf("Hello! It is Task1!\n"); + + Load(); + SaveResult(); +} \ No newline at end of file diff --git a/lr19/Project2/out.txt b/lr19/Project2/out.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/lr19/Project2/out.txt @@ -0,0 +1 @@ +0 diff --git a/lr19/lr19.sln b/lr19/lr19.sln new file mode 100644 index 0000000..1876a21 --- /dev/null +++ b/lr19/lr19.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35222.181 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lr19", "lr19\lr19.vcxproj", "{C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Debug|x64.ActiveCfg = Debug|x64 + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Debug|x64.Build.0 = Debug|x64 + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Debug|x86.ActiveCfg = Debug|Win32 + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Debug|x86.Build.0 = Debug|Win32 + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Release|x64.ActiveCfg = Release|x64 + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Release|x64.Build.0 = Release|x64 + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Release|x86.ActiveCfg = Release|Win32 + {C8DE0ED8-13B1-4FAB-A008-5B9FE6279EDC}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6B714702-849A-4B5C-8F18-E0D65EEC0BDC} + EndGlobalSection +EndGlobal diff --git a/lr19/lr19/Source.cpp b/lr19/lr19/Source.cpp new file mode 100644 index 0000000..2086001 --- /dev/null +++ b/lr19/lr19/Source.cpp @@ -0,0 +1,234 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include + +int* pa; +int a[1000]; //. 1000 - +int n; // + +void Load1() { + // + FILE* fin = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\in1.txt", "rt"); + if (fin == NULL) { + printf(" \n"); + return; + } + + // + fscanf(fin, "%d", &n); + for (int i = 0; i < n; i++) { + fscanf(fin, "%d", &a[i]); + } + + // + fclose(fin); +} + +void SaveResult1() { + // + float sa = 0; + float s = 0; + for (int i = 0; i < n; i++) { + s += a[i]; + } + sa = s / n; + + // , + int m = 0; + for (int i = 0; i < n; i++) { + if (a[i] > sa) { + m++; + } + } + + FILE* fout = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\out1.txt", "wt"); + if (fout == NULL) { + printf(" \n"); + return; + } + + // + fprintf(fout, "%d\n", m); + for (int i = 0; i < n; i++) { + if (a[i] > sa) { + fprintf(fout, "%d ", a[i]); + } + } + // + fclose(fout); +} + +void Load2() { + // + FILE* fin = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\in2.txt", "rt"); + if (fin == NULL) { + printf(" \n"); + return; + } + // + fscanf(fin, "%d", &n); + // + pa = (int*)malloc(sizeof(int) * n); + + for (int i = 0; i < n; i++) { + fscanf(fin, "%d", &pa[i]); + } + // + fclose(fin); +} + +void SaveResult2() { + // + float sa = 0; + float s = 0; + for (int i = 0; i < n; i++) { + s += pa[i]; + } + sa = s / n; + + // , + int m = 0; + for (int i = 0; i < n; i++) { + if (pa[i] > sa) { + m++; + } + } + + FILE* fout = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\out2.txt", "wt"); + if (fout == NULL) { + printf(" \n"); + return; + } + + // + fprintf(fout, "%d\n", m); + for (int i = 0; i < n; i++) { + if (pa[i] > sa) { + fprintf(fout, "%d ", pa[i]); + } + } + // + fclose(fout); +} + +void Load3() { + // + FILE* fin = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\in3.txt", "rt"); + if (fin == NULL) { + printf(" \n"); + return; + } + // + fscanf(fin, "%d", &n); + // + pa = (int*)malloc(sizeof(int) * n); + + for (int i = 0; i < n; i++) { + fscanf(fin, "%d", &pa[i]); + } + // + fclose(fin); +} + +void SaveResult3() { + // + float sa = 0; + float s = 0; + for (int i = 0; i < n; i++) { + s += pa[i]; + } + sa = s / n; + + // , + int m = 0; + for (int i = 0; i < n; i++) { + if (pa[i] < sa) { + if (pa[i] > 0) { + m++; + } + } + } + + FILE* fout = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\out3.txt", "wt"); + if (fout == NULL) { + printf(" \n"); + return; + } + + // + fprintf(fout, "%d\n", m); + for (int i = 0; i < n; i++) { + if (pa[i] < sa) { + if (pa[i] > 0) { + fprintf(fout, "%d ", pa[i]); + } + } + } + // + fclose(fout); +} + +void Load4() { + // + FILE* fin = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\in4.txt", "rt"); + if (fin == NULL) { + printf(" \n"); + return; + } + // + fscanf(fin, "%d", &n); + // + pa = (int*)malloc(sizeof(int) * n); + + for (int i = 0; i < n; i++) { + fscanf(fin, "%d", &pa[i]); + } + // + fclose(fin); +} + +void SaveResult4() { + // + float max23 = 0; + float max = 0; + for (int i = 0; i < n; i++) { + if (pa[i] > max) { + max = pa[i]; + } + } + max23 = (max / 3) * 2; + + // , + int m = 0; + for (int i = 0; i < n; i++) { + if (pa[i] >= max23) { + m++; + } + } + + FILE* fout = fopen("C:\\Users\\ivan\\Desktop\\lab_19\\out4.txt", "wt"); + if (fout == NULL) { + printf(" \n"); + return; + } + + // + fprintf(fout, "%d\n", m); + for (int i = 0; i < n; i++) { + if (pa[i] >= max23) { + fprintf(fout, "%d ", pa[i]); + } + } + // + fclose(fout); +} + + +void main() { + SetConsoleCP(1251); + SetConsoleOutputCP(1251); + printf("Hello! It is Task1!\n"); + + Load2(); + SaveResult2(); +} \ No newline at end of file diff --git a/lr19/lr19/lr19.vcxproj b/lr19/lr19/lr19.vcxproj new file mode 100644 index 0000000..53f6716 --- /dev/null +++ b/lr19/lr19/lr19.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {c8de0ed8-13b1-4fab-a008-5b9fe6279edc} + lr19 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/lr19/lr19/lr19.vcxproj.filters b/lr19/lr19/lr19.vcxproj.filters new file mode 100644 index 0000000..ef66db6 --- /dev/null +++ b/lr19/lr19/lr19.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file