Skip to content

Commit 1bfabf4

Browse files
authored
Laboratory work 1. The structure has been changed
The file structure of the project has been changed: - The implementation of the functions is placed in a separate file SetLab1_12_Kudashov.cpp - The main program file has been renamed to Lab1_12_Kudashov.cpp
1 parent 6d5befb commit 1bfabf4

File tree

10 files changed

+144
-24
lines changed

10 files changed

+144
-24
lines changed

laba_1/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ project(laba_1)
33

44
set(CMAKE_CXX_STANDARD 14)
55

6-
add_executable(laba_1 main.cpp)
6+
add_executable(laba_1 Lab1_12_Kudashov.cpp SetLab1_12_Kudashov.cpp SetLab1_12_Kudashov.h)

laba_1/Lab1_12_Kudashov.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "SetLab1_12_Kudashov.h"
2+
3+
int main() {
4+
srand( time(0) );
5+
Node* setA = creatingSet (rand() % 4 + 6, 5, 500, 5);
6+
cout << "Print set A: " << printSet(setA, " | ") << endl;
7+
cout << "Power set A: " << powerOfTheSet(setA) << endl;
8+
Node* setB = creatingSet (rand() % 4 + 6, 5, 500, 10);
9+
cout << "Print set B: " << printSet(setB, " | ") << endl;
10+
cout << "Power set B: " << powerOfTheSet(setB) << endl;
11+
deleteSet(setA);
12+
cout << "---------------After cleaning---------------" << endl;
13+
cout << "Print set A: " << printSet(setA, " | ") << endl;
14+
cout << "Power set A: " << powerOfTheSet(setA) << endl;
15+
deleteSet(setB);
16+
cout << "Print set B: " << printSet(setB, " | ") << endl;
17+
cout << "Power set B: " << powerOfTheSet(setB) << endl;
18+
return 0;
19+
}

laba_1/SetLab1_12_Kudashov.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "SetLab1_12_Kudashov.h"
2+
3+
// Создание пустого множества
4+
Node* creatingAnEmptySet() {
5+
Node* first = nullptr;
6+
return first;
7+
}
8+
// Проверка на пустое множество
9+
bool emptySet(Node* first) {
10+
return first == nullptr;
11+
}
12+
// Проверка принадлежности элемента множеству
13+
bool checkingOfExistence(Node* first, int checking_value) {
14+
if (emptySet(first)) return false;
15+
Node* current = first;
16+
while (current->next && current->value != checking_value)
17+
current = current->next;
18+
return current->value == checking_value;
19+
};
20+
// Добавление нового элемента в множество в начало списка
21+
Node* add(Node*& first, int adding_value) {
22+
if (!checkingOfExistence(first, adding_value)){
23+
Node* new_node = new Node;
24+
new_node->value = adding_value;
25+
new_node->next = emptySet(first) ? nullptr : first;
26+
first = new_node;
27+
}
28+
return first;
29+
}
30+
// Мощность множества
31+
int powerOfTheSet (Node* first) {
32+
int power = 0;
33+
if (emptySet(first)) return 0;
34+
Node* current = first;
35+
power++;
36+
while (current->next) {
37+
current = current->next;
38+
power++;
39+
}
40+
return power;
41+
}
42+
// Создание нового множества
43+
Node* creatingSet(int quantity, int min, int max, int k){
44+
Node* set = creatingAnEmptySet();
45+
// int k = 5; // коэффициент кратности
46+
// Множество А – множество чисел, кратных 5. Множество В – множество чисел, кратных 10.
47+
if (k*quantity <= max - min + 1){
48+
while (powerOfTheSet(set) < quantity){
49+
int temp = rand() % (max-min+1) + min;
50+
if (temp % k == 0)
51+
add(set, temp);
52+
}
53+
}
54+
else
55+
cout << "Creating a set is not possible!" << endl;
56+
return set;
57+
}
58+
// Вывод элементов множества
59+
string printSet(Node* first, string separator){
60+
if (emptySet(first)) return "Elements not found";
61+
Node* current = first;
62+
string print;
63+
while (current->next) {
64+
print += to_string(current->value) + separator;
65+
current = current->next;
66+
}
67+
print += to_string(current->value);
68+
return print;
69+
}
70+
// Удаление множества
71+
Node* deleteSet(Node*& first){
72+
Node* current = first;
73+
if (emptySet(first)) // Если список пуст, сообщить об этом
74+
cout << "The list is empty!" << endl;
75+
while (current) { // Удаление элементов, если они есть
76+
Node* temp = current;
77+
current = current->next;
78+
delete temp;
79+
}
80+
first = nullptr;
81+
return first;
82+
}

laba_1/SetLab1_12_Kudashov.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef LABA_1_SETLAB1_12_KUDASHOV_H
2+
#define LABA_1_SETLAB1_12_KUDASHOV_H
3+
#pragma once
4+
#include <iostream>
5+
#include <string>
6+
using namespace std;
7+
// Элемент списка
8+
struct Node {
9+
int value; // Данные - числовое значение
10+
Node* next; // Указатель на следующий элемент списка
11+
};
12+
// Создание пустого множества
13+
Node* creatingAnEmptySet();
14+
// Проверка на пустое множество
15+
bool emptySet(Node* first);
16+
// Проверка принадлежности элемента множеству
17+
bool checkingOfExistence(Node* first, int checking_value);
18+
// Добавление нового элемента в множество в начало списка
19+
Node* add(Node*& first, int adding_value);
20+
// Мощность множества
21+
int powerOfTheSet (Node* first);
22+
// Создание нового множества
23+
Node* creatingSet(int quantity, int min, int max, int k);
24+
// Вывод элементов множества
25+
string printSet(Node* first, string separator);
26+
// Удаление множества
27+
Node* deleteSet(Node*& first);
28+
#endif //LABA_1_SETLAB1_12_KUDASHOV_H
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
"C:\Program Files\JetBrains\CLion 2021.3.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2021.3.1/bin/ninja/win/ninja.exe" -G Ninja C:\Users\sasha\CLionProjects\laba_1
2-
-- The C compiler identification is GNU 11.2.0
3-
-- The CXX compiler identification is GNU 11.2.0
4-
-- Detecting C compiler ABI info
5-
-- Detecting C compiler ABI info - done
6-
-- Check for working C compiler: C:/Program Files/JetBrains/CLion 2021.3.1/bin/mingw/bin/gcc.exe - skipped
7-
-- Detecting C compile features
8-
-- Detecting C compile features - done
9-
-- Detecting CXX compiler ABI info
10-
-- Detecting CXX compiler ABI info - done
11-
-- Check for working CXX compiler: C:/Program Files/JetBrains/CLion 2021.3.1/bin/mingw/bin/g++.exe - skipped
12-
-- Detecting CXX compile features
13-
-- Detecting CXX compile features - done
142
-- Configuring done
153
-- Generating done
164
-- Build files have been written to: C:/Users/sasha/CLionProjects/laba_1/cmake-build-debug
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Start testing: Dec 26 12:56 RTZ 2 (ceia)
1+
Start testing: Dec 26 13:46 RTZ 2 (ceia)
22
----------------------------------------------------------
3-
End testing: Dec 26 12:56 RTZ 2 (ceia)
3+
End testing: Dec 26 13:46 RTZ 2 (ceia)

laba_1/cmake-build-debug/build.ninja

Lines changed: 12 additions & 9 deletions
Large diffs are not rendered by default.
44.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)