-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
201 lines (159 loc) · 3.9 KB
/
main.cpp
File metadata and controls
201 lines (159 loc) · 3.9 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <iostream>
#include "SortedArray.h"
using namespace std;
int main()
{
// experiment 10
SortedArray arr_1(7);
for (int i = 0; i < 7; i++)
arr_1.setat(i, 7 - i);
unsigned int temp = arr_1[3];
unsigned int temp2 = arr_1.getat(2);
cout << "Elements of arr_1 are " << endl;
cout << arr_1 << endl;
cout << "arr_1[3] = " << temp<< endl;
cout << "arr_1[2] = " << temp2 << endl;
/*
// experiment 9
// Another experiment for []
SortedArray arr_1(7);
SortedArray arr_2(5);
for (int i = 0; i < 7; i++)
arr_1.setat(i, 7 - i);
arr_2[0] = arr_1[1];
cout << arr_1[1] << endl;
cout << arr_2[0] << endl;
*/
/*
// experiment 8
// Testing the assignment operator
SortedArray arr_1(7);
for (int i = 0; i < 7; i++)
arr_1.setat(i, 7-i);
SortedArray arr_2(5);
arr_2[3] = 3;
arr_2[2] = 1;
arr_1 = arr_2;
cout << "Elements of arr_2 are: " << endl;
cout << arr_2 << endl;
cout << "Elements of arr_1 are: " << endl;
cout << arr_1 << endl;
*/
/*
// experiment 7
// Testing equality operator
SortedArray arr_1(7);
SortedArray arr_2(5);
for (int i = 0; i < 7; i++)
arr_1[i] = i;
for (int i = 0; i < 5; i++)
arr_2[i] = 2+i;
if (arr_1 == arr_2)
cout << "The 2 arrays are equal to eachother " << endl;
else
cout << "The 2 arrays aren't equal to eachother " << endl;
*/
/*
// experiment 6
// Testing output stream operator and square operator
SortedArray arr_1(5);
for (int i = 0; i < 5; i++)
arr_1[i] = 4-i;
cout << arr_1 << endl;
*/
/*
// experiment 5
// Error reporting to client if he attempts to insert a negative element to the array
try {
SortedArray arr_1(20);
arr_1[5] = -8;
}
catch (exception_type ex)
{
switch (ex)
{
case INVALID_ARGUMENT:
cout << "Can't insert a negative entry inside the array!!" << endl;
break;
case MEMORY_ALLOCATION_FAILURE:
cout << "Failed to allocate memory!!" << endl;
break;
case EMPTY_ENTRY:
cout << "This entry isn't yet set, so is invalid! Can't retrieve an invalid entry!!" << endl;
break;
}
}
*/
/*
// experiment 4
// Error Reporting for accessing element that was set but because of sorting it moved
try {
SortedArray arr_1(20);
arr_1[5] = 9;
cout << "To maintain sorting the value is moved to the beginning of the array : " << endl << arr_1[0] << endl;
unsigned int temp = arr_1[5];
}
catch (exception_type ex)
{
switch (ex)
{
case INVALID_ARGUMENT:
cout << "The chosen index is out of bounds!!" << endl;
break;
case MEMORY_ALLOCATION_FAILURE:
cout << "Failed to allocate memory!!" << endl;
break;
case EMPTY_ENTRY:
cout << "This entry isn't yet set, so is invalid! Can't retrieve an invalid entry!!" << endl;
break;
}
}
*/
/*
// experiment 2 and 3
// Error Reporting for accessing elements at -ve index
try {
SortedArray arr_1(20);
unsigned int temp = arr_1[20];
}
catch (exception_type ex)
{
switch (ex)
{
case INVALID_ARGUMENT:
cout << "The chosen index is out of bounds!!" << endl;
break;
case MEMORY_ALLOCATION_FAILURE:
cout << "Failed to allocate memory!!" << endl;
break;
case EMPTY_ENTRY:
cout << "This entry isn't yet set, so is invalid! Can't retrieve an invalid entry!!" << endl;
break;
}
}
*/
/*
// experiment 1
// Error Reporting for arrays with -ve sizes
try {
SortedArray arr_1(-5);
}
catch (exception_type ex)
{
switch (ex)
{
case INVALID_ARGUMENT:
cout << "The chosen index is out of bounds!!" << endl;
break;
case MEMORY_ALLOCATION_FAILURE:
cout << "Failed to allocate memory!!" << endl;
break;
case EMPTY_ENTRY:
cout << "This entry isn't yet set, so is invalid! Can't retrieve an invalid entry!!" << endl;
break;
}
}
*/
system("pause");
return 0;
}