-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes(reflexive-association).cpp
76 lines (64 loc) · 1.43 KB
/
classes(reflexive-association).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
class roboust {
private:
roboust* a;
int* numbers, total_numbers;
public:
roboust() {
a = nullptr;
total_numbers = 0;
numbers = new int[total_numbers];
}
void add(int n) {
int* temp_arr = new int[total_numbers + 1];
for (int i = 0; i < total_numbers; i++) {
temp_arr[i] = numbers[i];
}
temp_arr[total_numbers] = n;
delete[] numbers;
numbers = temp_arr;
total_numbers++;
}
//getters and setters
roboust get() {
return *a;
}
void set(roboust a) {
*this->a = roboust(a);
}
roboust(roboust &r) {
total_numbers = r.total_numbers;
int* temp_arr = new int[total_numbers];
for (int i = 0; i < total_numbers; i++) {
temp_arr[i] = r.numbers[i];
}
delete[] numbers;
numbers = temp_arr;
}
friend ostream& operator<<(ostream& out, roboust& r)
{
for (int i = 0; i < r.total_numbers; i++) {
out << r.numbers[i] << " ";
}
return out;
}
void display() {
for (int i = 0; i < total_numbers; i++) {
cout << numbers[i] << " ";
}
}
};
int main() {
//implementation
roboust a;
a.add(1);
a.add(43);
a.add(-6);
a.add(16);
a.add(23);
a.add(-61);
roboust b(a);
b.display();
return 0;
}