From de343e911e46a40fa6a00234deceb5096323a2f1 Mon Sep 17 00:00:00 2001 From: Fasterino Date: Wed, 25 Feb 2026 18:10:23 +0300 Subject: [PATCH] Initial commit --- .gitignore | 4 ++ CMakeLists.txt | 30 ++++++++++++++ include/labs.h | 19 +++++++++ src/funcs.cpp | 20 ++++++++++ src/lab1.cpp | 21 ++++++++++ src/lab2.cpp | 29 ++++++++++++++ src/lab3.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lab4.cpp | 50 +++++++++++++++++++++++ src/lab5.cpp | 56 ++++++++++++++++++++++++++ src/lab6.cpp | 62 +++++++++++++++++++++++++++++ src/main.cpp | 24 +++++++++++ 11 files changed, 421 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 include/labs.h create mode 100644 src/funcs.cpp create mode 100644 src/lab1.cpp create mode 100644 src/lab2.cpp create mode 100644 src/lab3.cpp create mode 100644 src/lab4.cpp create mode 100644 src/lab5.cpp create mode 100644 src/lab6.cpp create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a118d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/CMakeCache* +/build +.vscode +.DS_Store \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..55b1f53 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.20) + +# === Название проекта === +project(gorshkov_lab_1_6 VERSION 1.0 LANGUAGES CXX) + +# === Настройки компиляции === +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# === Пути к исходникам и заголовкам === +set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") +set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") + +# === Рекурсивный поиск исходников === +file(GLOB_RECURSE SOURCES "${SRC_DIR}/*.cpp") + +# === Создание исполняемого файла === +add_executable(${PROJECT_NAME} ${SOURCES}) + +# === Добавляем include-директорию === +target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR}) + +# === Рекомендованные предупреждения === +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /permissive-) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic) +endif() + diff --git a/include/labs.h b/include/labs.h new file mode 100644 index 0000000..62237f5 --- /dev/null +++ b/include/labs.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +using namespace std; + +#define loop while (1) + +using LabF = function; + +void lab1(); +void lab2(); +void lab3(); +void lab4(); +void lab5(); +void lab6(); + +double lab12_f1(double x); +double lab12_f2(double v, double w); \ No newline at end of file diff --git a/src/funcs.cpp b/src/funcs.cpp new file mode 100644 index 0000000..5a22996 --- /dev/null +++ b/src/funcs.cpp @@ -0,0 +1,20 @@ +#include + +double lab12_f1(double x) +{ + if (x < 2.5) + return sqrt(abs(sin(x)) + 15.0) / 4.0; + + return sqrt(abs(sin(x)) + 15.0) / 2.0; +} + +double lab12_f2(double v, double w) +{ + if (w < 2) + return v - w * w; + + if (w < 3) + return v * v - w; + + return v; +} \ No newline at end of file diff --git a/src/lab1.cpp b/src/lab1.cpp new file mode 100644 index 0000000..fa8887e --- /dev/null +++ b/src/lab1.cpp @@ -0,0 +1,21 @@ +#include + +void lab1() +{ + double x, y, z, v, w; + + cout << "Enter x: "; + cin >> x; + + y = lab12_f1(x); + + cout << "Result y(" << x << ") = " << y << endl + << endl; + + v = x; + cout << "V = " << v << endl; + cout << "Enter W: "; + cin >> w; + z = lab12_f2(v, w); + cout << "Result Z(" << v << ", " << w << ") = " << z << endl; +} \ No newline at end of file diff --git a/src/lab2.cpp b/src/lab2.cpp new file mode 100644 index 0000000..9f262da --- /dev/null +++ b/src/lab2.cpp @@ -0,0 +1,29 @@ +#include + +void lab2() +{ + double v, w, z, w_min, w_max; + int c; + + cout << "Enter V: "; + cin >> v; + + cout << "Enter W min: "; + cin >> w_min; + cout << "Enter W max: "; + cin >> w_max; + + cout << "Enter count of points: "; + cin >> c; + + for (int i = 0; i < c; i++) + { + cout << endl; + + w = w_min + (w_max - w_min) * ((double)i / (c - 1)); + cout << i + 1 << ". W = " << w << endl; + + z = lab12_f2(v, w); + cout << "Result Z(" << v << ", " << w << ") = " << z << endl; + } +} \ No newline at end of file diff --git a/src/lab3.cpp b/src/lab3.cpp new file mode 100644 index 0000000..43ea5c8 --- /dev/null +++ b/src/lab3.cpp @@ -0,0 +1,106 @@ +#include + +using IterationF = function; +using LoopF = function; + +double iteration(double x, double i); +double mp_for(int min, int max, IterationF &f); +double mp_while(int min, int max, IterationF &f); +double mp_do_while(int min, int max, IterationF &f); + +void lab3() +{ + LoopF loopF; + IterationF f; + double x, y; + int n; + char c; + + cout << "Enter x: "; + cin >> x; + + f = [=](int i) + { return iteration(x, i); }; + + cout + << "Enter N: "; + cin >> n; + + loop // while (1) + { + cout << endl + << "Select mode (F/W/D): "; + cin >> c; + + switch (c) + { + case 'f': + case 'F': + loopF = mp_for; + break; + case 'w': + case 'W': + loopF = mp_while; + break; + case 'd': + case 'D': + loopF = mp_do_while; + break; + + default: + cout << "Invalid mode, exiting!" << endl; + return; + } + + y = pow(loopF(1, n, f), 1.2 * x); + cout << "Result y(" << x << ") = " << y << endl; + } +} + +double iteration(double x, double i) +{ + return 2.8 * pow(x, 4.5) + cbrt(i); +} + +double mp_for(int min, int max, IterationF &f) +{ + double res = 1.0; + + for (int i = min; i <= max; i++) + { + res += f(i); + } + + return res; +} + +double mp_while(int min, int max, IterationF &f) +{ + double res = 1.0; + + int i = min; + while (i <= max) + { + res += f(i); + i++; + } + + return res; +} + +double mp_do_while(int min, int max, IterationF &f) +{ + double res = 1.0; + + if (min >= max) + return res; + + int i = min; + do + { + res += f(i); + i++; + } while (i <= max); + + return res; +} \ No newline at end of file diff --git a/src/lab4.cpp b/src/lab4.cpp new file mode 100644 index 0000000..1ae04a1 --- /dev/null +++ b/src/lab4.cpp @@ -0,0 +1,50 @@ +#include + +constexpr size_t LEN = 15; + +void lab4() +{ + int arr[LEN], d_min, d_max, sum; + size_t len; + + cout << "Enter range min: "; + cin >> d_min; + + cout << "Enter range max: "; + cin >> d_max; + + cout << "Enter size of array (0-" << LEN << "): "; + cin >> len; + + if (len > LEN) + { + cout << "Invalid size, exiting!" << endl; + return; + } + + for (size_t i = 0; i < len; i++) + { + cout << "Enter arr[" << i << "]: "; + cin >> arr[i]; + } + + sum = 0; + for (size_t i = 0; i < len; i++) + { + if (d_min <= arr[i] && arr[i] <= d_max) + sum += arr[i]; + } + + cout << "Arr is { "; + for (size_t i = 0; i < len; i++) + { + cout << arr[i]; + + if (i < len - 1) + cout << ", "; + else + cout << " "; + } + cout << "}" << endl; + cout << "Sum of elements in range [" << d_min << "; " << d_max << "] is " << sum << endl; +} \ No newline at end of file diff --git a/src/lab5.cpp b/src/lab5.cpp new file mode 100644 index 0000000..c0a3299 --- /dev/null +++ b/src/lab5.cpp @@ -0,0 +1,56 @@ +#include + +constexpr size_t LEN = 5; + +void lab5() +{ + int arr[LEN][LEN], d_min, d_max, d_count, v_max_i, v_max_j; + + cout << "Enter range min: "; + cin >> d_min; + + cout << "Enter range max: "; + cin >> d_max; + + for (size_t i = 0; i < LEN; i++) + for (size_t j = 0; j < LEN; j++) + { + cout << "Enter arr[" << i << "][" << j << "]: "; + cin >> arr[i][j]; + } + + v_max_i = v_max_j = 0; + + d_count = 0; + + for (size_t i = 0; i < LEN; i++) + for (size_t j = 0; j < LEN; j++) + { + if (d_min <= arr[i][j] && arr[i][j] <= d_max) + d_count++; + + if (arr[i][j] > arr[v_max_i][v_max_j]) + { + v_max_i = i; + v_max_j = j; + } + } + + cout << "Matrix is {" << endl; + for (size_t i = 0; i < LEN; i++) + { + + for (size_t j = 0; j < LEN; j++) + { + + cout << '\t' << arr[i][j]; + + if (j < LEN - 1) + cout << ","; + } + cout << endl; + } + cout << "}" << endl; + cout << "Number of elements in range [" << d_min << "; " << d_max << "] is " << d_count << endl; + cout << "Highest element in array is arr[" << v_max_i << "][" << v_max_j << "] = " << arr[v_max_i][v_max_j] << endl; +} \ No newline at end of file diff --git a/src/lab6.cpp b/src/lab6.cpp new file mode 100644 index 0000000..094f09d --- /dev/null +++ b/src/lab6.cpp @@ -0,0 +1,62 @@ +#include + +template +void make_array(); +void print_array(double array[], size_t len); + +void lab6() +{ + make_array<3>(); + make_array<4>(); + make_array<5>(); +} + +template +void make_array() +{ + cout << "Making an array with size: " << LEN << endl; + double arr[LEN], v_min, v_max, d; + + for (size_t i = 0; i < LEN; i++) + { + cout << "Enter arr[" << i << "]: "; + cin >> arr[i]; + } + + print_array(arr, LEN); + + for (size_t i = 0; i < LEN; i++) + { + arr[i] /= 2.0; + } + + v_min = v_max = arr[0]; + for (size_t i = 0; i < LEN; i++) + { + if (arr[i] < v_min) + v_min = arr[i]; + if (arr[i] > v_max) + v_max = arr[i]; + } + + print_array(arr, LEN); + + d = v_max - v_min; + cout << "Result: D = " << d << endl + << endl; +} + +void print_array(double arr[], size_t len) +{ + cout << "Arr is { "; + for (size_t i = 0; i < len; i++) + { + cout << arr[i]; + + if (i < len - 1) + cout << ", "; + else + cout << " "; + } + cout << "}" << endl; +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..4ae1d26 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,24 @@ +#include + +double lab12_f1(double x); + +constexpr size_t LEN = 6; +static LabF LABS[LEN] = {lab1, lab2, lab3, lab4, lab5, lab6}; + +int main() +{ + size_t choice; + cout << "Choose lab (1-6): "; + cin >> choice; + cout << endl; + + if (choice < 1 || choice > LEN) + { + cout << "Lab " << choice << " not exists, exiting!" << endl; + return 1; + } + + LABS[choice - 1](); + + return 0; +}