Skip to content

Commit e2556f7

Browse files
authored
Laboratory work 2
1 parent a795829 commit e2556f7

File tree

7 files changed

+111
-15
lines changed

7 files changed

+111
-15
lines changed

laba_1/Lab1_12_Kudashov.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
#include "SetLab1_12_Kudashov.h"
2-
2+
#include <clocale> //Обязательно для функции setlocale()
33
int main() {
4-
srand( time(0) );
4+
srand( time(nullptr) );
5+
setlocale(LC_ALL, "Russian");
6+
cout << "=================ДЕМО ЛАБЫ 1=================" << endl;
57
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+
cout << "Вывод множества A: " << endl << printSet(setA, " | ") << endl;
9+
cout << "Мощность множества A: " << endl << powerOfTheSet(setA) << endl;
810
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+
cout << "Вывод множества B: " << endl << printSet(setB, " | ") << endl;
12+
cout << "Мощность множества B: " << endl << powerOfTheSet(setB) << endl;
13+
cout << "----------------После очистки----------------" << endl;
1114
deleteSet(setA);
12-
cout << "---------------After cleaning---------------" << endl;
13-
cout << "Print set A: " << printSet(setA, " | ") << endl;
14-
cout << "Power set A: " << powerOfTheSet(setA) << endl;
15+
cout << "Вывод множества A: " << endl << printSet(setA, " | ") << endl;
16+
cout << "Мощность множества A: " << endl << powerOfTheSet(setA) << endl;
1517
deleteSet(setB);
16-
cout << "Print set B: " << printSet(setB, " | ") << endl;
17-
cout << "Power set B: " << powerOfTheSet(setB) << endl;
18+
cout << "Вывод множества B: " << endl << printSet(setB, " | ") << endl;
19+
cout << "Мощность множества B: " << endl << powerOfTheSet(setB) << endl;
20+
cout << endl << "=================ДЕМО ЛАБЫ 2=================" << endl;
21+
Node* A = creatingSet (rand() % 4 + 6, 5, 200, 10);
22+
Node* B = creatingSet (rand() % 4 + 6, 5, 200, 5);
23+
cout << "Вывод множества A: " << endl << printSet(A, " | ") << endl;
24+
cout << "Вывод множества B: " << endl << printSet(B, " | ") << endl;
25+
cout << "Является ли A подмножеством B: " << isSubset(A,B) << endl;
26+
cout << "Равны ли множества A и B" << isEqual(A,B) << endl;
27+
Node* C = combiningSets(A,B);
28+
cout << "Вывод объединения множеств: " << endl << printSet(C, " | ") << endl;
29+
Node* D = intersectionOfSets(A,B);
30+
cout << "Вывод пересечения множеств: " << endl << printSet(D, " | ") << endl;
31+
Node* E = differenceOfSets(A,B);
32+
cout << "Вывод разности множеств A и B: " << endl << printSet(E, " | ") << endl;
33+
Node* F = differenceOfSets(B,A);
34+
cout << "Вывод разности множеств B и A: " << endl << printSet(F, " | ") << endl;
35+
Node* G = symmetricDifferenceOfSets(A,B);
36+
cout << "Вывод симметричной разности множеств: " << endl << printSet(G, " | ") << endl;
1837
return 0;
1938
}

laba_1/SetLab1_12_Kudashov.cpp

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Node* add(Node*& first, int adding_value) {
2222
if (!checkingOfExistence(first, adding_value)){
2323
Node* new_node = new Node;
2424
new_node->value = adding_value;
25-
new_node->next = emptySet(first) ? nullptr : first;
25+
new_node->next = first;
2626
first = new_node;
2727
}
2828
return first;
@@ -42,7 +42,7 @@ int powerOfTheSet (Node* first) {
4242
// Создание нового множества
4343
Node* creatingSet(int quantity, int min, int max, int k){
4444
Node* set = creatingAnEmptySet();
45-
// int k = 5; // коэффициент кратности
45+
// k - коэффициент кратности
4646
// Множество А – множество чисел, кратных 5. Множество В – множество чисел, кратных 10.
4747
if (k*quantity <= max - min + 1){
4848
while (powerOfTheSet(set) < quantity){
@@ -79,4 +79,69 @@ Node* deleteSet(Node*& first){
7979
}
8080
first = nullptr;
8181
return first;
82+
}
83+
// Является ли A подмножеством B
84+
bool isSubset(Node* A, Node* B){
85+
if (emptySet(A)) return true;
86+
if (powerOfTheSet(A) > powerOfTheSet(B)) return false;
87+
Node* current = A;
88+
while (current->next){
89+
if(!checkingOfExistence(B, current->value))
90+
return false;
91+
current = current->next;
92+
}
93+
return true;
94+
}
95+
// Проверка множеств на равенство
96+
bool isEqual(Node* A, Node* B){
97+
return isSubset(A,B) && (powerOfTheSet(A) == powerOfTheSet(B));
98+
}
99+
// Объединение множеств
100+
Node* combiningSets(Node* A, Node* B){
101+
if (emptySet(A) || emptySet(B))
102+
return creatingAnEmptySet();;
103+
Node* C = A;
104+
Node* current = B;
105+
while (current->next) {
106+
if(!checkingOfExistence(C, current->value))
107+
C = add(C, current->value);
108+
current = current->next;
109+
}
110+
if(checkingOfExistence(B, current->value))
111+
C = add(C, current->value);
112+
return C;
113+
}
114+
// Пересечение множеств
115+
Node* intersectionOfSets(Node* A, Node* B){
116+
if (emptySet(A) || emptySet(B))
117+
return creatingAnEmptySet();;
118+
Node* C = creatingAnEmptySet();
119+
Node* current = A;
120+
while (current->next){
121+
if(checkingOfExistence(B, current->value))
122+
C = add(C, current->value);
123+
current = current->next;
124+
}
125+
if(checkingOfExistence(B, current->value))
126+
C = add(C, current->value);
127+
return C;
128+
}
129+
// Разность множеств
130+
Node* differenceOfSets(Node* A, Node* B){
131+
if (emptySet(A) || emptySet(B))
132+
return creatingAnEmptySet();
133+
Node* C = creatingAnEmptySet();
134+
Node* current = A;
135+
while (current->next){
136+
if(!checkingOfExistence(B, current->value))
137+
C = add(C, current->value);
138+
current = current->next;
139+
}
140+
if(!checkingOfExistence(B, current->value))
141+
C = add(C, current->value);
142+
return C;
143+
}
144+
// Симметричная разность множеств
145+
Node* symmetricDifferenceOfSets(Node* A, Node* B){
146+
return differenceOfSets(combiningSets(A,B), intersectionOfSets(A,B));
82147
}

laba_1/SetLab1_12_Kudashov.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,16 @@ Node* creatingSet(int quantity, int min, int max, int k);
2525
string printSet(Node* first, string separator);
2626
// Удаление множества
2727
Node* deleteSet(Node*& first);
28+
// Является ли A подмножеством B
29+
bool isSubset(Node* A, Node* B);
30+
// Проверка множеств на равенство
31+
bool isEqual(Node* A, Node* B);
32+
// Объединение множеств
33+
Node* combiningSets(Node* A, Node* B);
34+
// Пересечение множеств
35+
Node* intersectionOfSets(Node* A, Node* B);
36+
// Разность множеств
37+
Node* differenceOfSets(Node* A, Node* B);
38+
// Симметричная разность множеств
39+
Node* symmetricDifferenceOfSets(Node* A, Node* B);
2840
#endif //LABA_1_SETLAB1_12_KUDASHOV_H
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 13:46 RTZ 2 (ceia)
1+
Start testing: Feb 18 17:32 RTZ 2 (ceia)
22
----------------------------------------------------------
3-
End testing: Dec 26 13:46 RTZ 2 (ceia)
3+
End testing: Feb 18 17:32 RTZ 2 (ceia)
8.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)