Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .vs/CMake Overview
Empty file.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "x64-Debug (по умолчанию)"
}
10 changes: 10 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\include",
"\\src",
"\\tests"
],
"SelectedNode": "\\src\\tasks.cpp",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/h00_cpp_basics-UnluckyDen/v16/.suo
Binary file not shown.
Binary file added .vs/h00_cpp_basics-UnluckyDen/v16/Browse.VC.db
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Задание 0: Основы C++

## ФИО студента
**TODO - Пожалуйста, добавьте сюда свое ФИО**
Гладких Даниил Сергеевич

## Описание заданий

Expand Down
111 changes: 92 additions & 19 deletions src/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,117 @@ using std::copy;
// Задание 1
void swap_args(int *lhs, int *rhs) {
// напишите код здесь ...
if ((lhs != nullptr) && (rhs != nullptr))
{
*lhs = *lhs + *rhs;
*rhs = *lhs - *rhs;
*lhs = *lhs - *rhs;
}
}

// Задание 2
int **allocate_2d_array(int num_rows, int num_cols, int init_value) {
// напишите код здесь ...
return nullptr;
int** allocate_2d_array(int rows, int cols, int value)
{
if ((rows >= 1) && (cols >= 1))
{
int** array_2d = new int* [rows];
for (int row_num = 0; row_num < rows; row_num++)
{
array_2d[row_num] = new int[cols] {};
}
for (int row_num = 0; row_num < rows; row_num++)
{
for (int cols_num = 0; cols_num < cols; cols_num++)
{
array_2d[row_num][cols_num] = value;
}
}
return array_2d;
}
else
{
return nullptr;
}
}

// Задание 3
bool copy_2d_array(int **arr_2d_source, int **arr_2d_target, int num_rows, int num_cols) {
// напишите код здесь ...
return false;
bool copy_2d_array(int** arr_2d_source, int** arr_2d_target, int num_rows, int num_cols) {
if ((arr_2d_source == nullptr) || (arr_2d_target == nullptr) || (num_rows <= 0) || (num_cols <= 0)) {
return false;
}
else {
for (int i = 0; i < num_rows; i++) {
copy(arr_2d_source[i], arr_2d_source[i] + num_cols, arr_2d_target[i]);
}
} return true;
}

// Задание 4
void reverse_1d_array(vector<int> &arr) {
// напишите код здесь ...
vector<int> vec;
for (int elem = arr.size() - 1; elem != -1; elem--) {
int temp = arr[elem];
vec.push_back(arr[elem]);
}
for (int elem = 0; elem < arr.size(); elem++) {
arr[elem] = vec[elem];
}
}


// Задание 5
void reverse_1d_array(int *arr_begin, int *arr_end) {
// напишите код здесь ...
void reverse_1d_array(int* arr_begin, int* arr_end) {
if ((arr_begin == nullptr) || (arr_end == nullptr)) {
}
else {
while (arr_begin < arr_end) {
int temp = *arr_begin;
*arr_begin = *arr_end;
*arr_end = temp;
arr_begin++;
arr_end--;
}
}
}

// Задание 6
int *find_max_element(int *arr, int size) {
// напишите код здесь ...
return nullptr;
int* find_max_element(int* arr, int size) {
if ((arr == nullptr) || (size <= 0)) {
return nullptr;
}
else {
int* max = arr;
for (int i = 0; i < size; i++) {
if (*arr > *max) {
max = arr;
}
arr++;
}
return max;
}

}

// Задание 7
vector<int> find_odd_numbers(vector<int> &arr) {
// напишите код здесь ...
return {};
vector<int> find_odd_numbers(vector<int>& arr) {
for (int i = 0; i < arr.size(); i++) {
if (arr[i] % 2 == 0) {
arr.erase(arr.begin() + i);
i--;
}
}
return arr;
}

// Задание 8
vector<int> find_common_elements(vector<int> &arr_a, vector<int> &arr_b) {
// напишите код здесь ...
return {};
}
vector<int> find_common_elements(vector<int>& arr_a, vector<int>& arr_b) {
vector<int> array;
for (int i = 0; i < arr_a.size(); i++) {
for (int j = 0;j < arr_b.size(); j++) {
if (arr_a[i] == arr_b[j]) {
array.insert(array.end(), arr_a[i]);
}
}
}
return array;
}