Частина тексту файла (без зображень, графіків і формул):
Міністерство освіти і науки України
Національний університет «Львівська політехніка»
Кафедра ІСМ
/
Звіт
Про виконання
Лабораторної роботи №2
З дисципліни: «Об’єктно-орієнтоване програмування»
На тему: «Оголошення та структура класу»Варіант 15
Львів 2015
Мета роботи: вивчити оголошення класу та рівнів захисту його елементів.
Завдання:
Код програми:#include <iostream>
using namespace std;
class set
{
private:
int* x = new int[100];
int tos=0;
public:
set()
{
for (int i = 0; i < 5; ++i)
x[i] = i + 1;
tos = 5;
}
set(int* y)
{
while (y[tos]>-3000000)
{
x[tos] = y[tos];
tos++;
}
}
~set()
{
}
void add(int y)
{
x[tos] = y;
tos++;
}
void out()
{
cout << "Set: ";
for (int i = 0; i < tos; i++)
cout << x[i] << " ";
cout << endl;
}
bool contains(int y)
{
for (int i = 0; i < tos;i++)
if (x[i] == y) return true;
return false;
}
bool contains(int el, int* arr)
{
for (int i = 0; i < 100; ++i)
if (arr[i] == el) return true;
return false;
}
int* getArr()
{
return x;
}
int getTos()
{
return tos;
}
void obyednannya(set s)
{
int n = s.getTos();
int* tmp = s.getArr();
for (int i = 0; i < n; ++i)
if (!(contains(tmp[i])))
add(tmp[i]);
}
set riznycya(set s1, set s2)
{
int k = 0;
int* res = new int[100];
for (int i = 0; i < s1.tos;++i)
if (!(contains(s1.x[i], s2.x)))
{
res[k++] = s1.x[i];
}
set result = set(res);
return result;
}
set peretyn(set s1, set s2)
{
int* res = new int[100];
int k = 0;
for (int i = 0; i < s1.tos; ++i)
if (contains(s1.x[i], s2.x))
{
res[k++] = s1.x[i];
}
set result = set(res);
return result;
}
};
int main()
{
set s1 = set();
int* xs = new int [3] {1, 21, 11};
set s2 = set(xs);
set s3;
s3 = s3.peretyn(s1, s2);
s3.out();
set s4;
s4 = s4.riznycya(s3, s2);
s4.out();
s4.obyednannya(s1);
s4.out();
set s5;
s5 = s5.riznycya(s2, s1);
s5.out();
s5.add(1234);
s5.out();
system("pause");
return 0;
}
Результат компіляції:
Висновок: під час виконання лабораторної роботи, я згадав стандартні операції над множинами і реалізував їх мовою С++.