Initial commit
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/CMakeCache*
|
||||||
|
/build
|
||||||
|
.vscode
|
||||||
|
.DS_Store
|
||||||
30
CMakeLists.txt
Normal file
30
CMakeLists.txt
Normal file
@@ -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()
|
||||||
|
|
||||||
19
include/labs.h
Normal file
19
include/labs.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define loop while (1)
|
||||||
|
|
||||||
|
using LabF = function<void()>;
|
||||||
|
|
||||||
|
void lab1();
|
||||||
|
void lab2();
|
||||||
|
void lab3();
|
||||||
|
void lab4();
|
||||||
|
void lab5();
|
||||||
|
void lab6();
|
||||||
|
|
||||||
|
double lab12_f1(double x);
|
||||||
|
double lab12_f2(double v, double w);
|
||||||
20
src/funcs.cpp
Normal file
20
src/funcs.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
21
src/lab1.cpp
Normal file
21
src/lab1.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
29
src/lab2.cpp
Normal file
29
src/lab2.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
106
src/lab3.cpp
Normal file
106
src/lab3.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
using IterationF = function<double(int i)>;
|
||||||
|
using LoopF = function<double(int min, int max, IterationF &f)>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
50
src/lab4.cpp
Normal file
50
src/lab4.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
56
src/lab5.cpp
Normal file
56
src/lab5.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
62
src/lab6.cpp
Normal file
62
src/lab6.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
template <size_t LEN>
|
||||||
|
void make_array();
|
||||||
|
void print_array(double array[], size_t len);
|
||||||
|
|
||||||
|
void lab6()
|
||||||
|
{
|
||||||
|
make_array<3>();
|
||||||
|
make_array<4>();
|
||||||
|
make_array<5>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t LEN>
|
||||||
|
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;
|
||||||
|
}
|
||||||
24
src/main.cpp
Normal file
24
src/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <labs.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user