This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoint_driver.cpp
355 lines (330 loc) · 17.9 KB
/
point_driver.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
* file: point_driver.cpp
* type: C++ (source file)
* date: 31_JULY_2022
* author: Karlina Ray Beringer
* license: PUBLIC_DOMAIN
*/
#include "point.h" // Include the C++ header file which contains preprocessing directives, variable declarations, and function prototypes for the POINT class.
/** Declare function prototypes (function declarations and not function definitions) which pertain to program unit tests. */
void unit_test_0(std::ostream & output);
void unit_test_1(std::ostream & output);
void unit_test_2(std::ostream & output);
void unit_test_3(std::ostream & output);
void unit_test_4(std::ostream & output);
void unit_test_5(std::ostream & output);
void unit_test_6(std::ostream & output);
void unit_test_7(std::ostream & output);
void unit_test_8(std::ostream & output);
void unit_test_9(std::ostream & output);
void unit_test_10(std::ostream & output);
void unit_test_11(std::ostream & output);
void unit_test_12(std::ostream & output);
// Unit Test # 0: POINT class default constructor, POINT class print method, and POINT class destructor.
void unit_test_0(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 0: POINT class default constructor, POINT class print method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point;";
output << "\npoint.print(output);";
POINT point;
point.print(output);
}
// Unit Test # 1: POINT class default constructor, POINT class print method (with default parameter), and POINT class destructor.
void unit_test_1(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 1: POINT class default constructor, POINT class print method (with default parameter), and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point;";
output << "\npoint.print(); // Standard command line output (std::cout) is the default parameter for the POINT print method.";
POINT point;
point.print(); // Standard command line output (std::cout) is the default parameter for the POINT print method.
}
// Unit Test # 2: POINT class default constructor, POINT class overloaded ostream operator method (which is functionally the same as POINT class print method), and POINT class destructor.
void unit_test_2(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 2: POINT class default constructor, POINT class overloaded ostream operator method (which is functionally the same as POINT class print method), and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point;";
output << "\noutput << point; // functionally equivalent to: point.print(output);";
POINT point;
output << point;
}
// Unit Test # 3: POINT class default constructor (using the function explicity rather than implicitly), POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_3(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 3: POINT class default constructor (using that function explicity rather than implicitly), POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point = POINT(); // functionally equivalent to: POINT point;";
output << "\noutput << point;";
POINT point = POINT();
output << point;
}
// Unit Test # 4: POINT class normal constructor (using only valid function inputs), POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_4(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 4: POINT class normal constructor (using only valid function inputs), POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point = POINT(-503,404);";
output << "\noutput << point;";
POINT point = POINT(-503,404);
output << point;
}
// Unit Test # 5: POINT class normal constructor (using only valid function inputs), POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_5(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 5: POINT class normal constructor (using only valid function inputs), POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point_0 = POINT(-999,-999);";
output << "\nPOINT point_1 = POINT(999, 999);";
output << "\nPOINT point_2 = POINT(-999, 999);";
output << "\nPOINT point_3 = POINT(999, -999);";
output << "\noutput << point_0;";
output << "\noutput << point_1;";
output << "\noutput << point_2;";
output << "\noutput << point_3;";
POINT point_0 = POINT(-999,-999);
POINT point_1 = POINT(999, 999);
POINT point_2 = POINT(-999, 999);
POINT point_3 = POINT(999, -999);
output << point_0;
output << point_1;
output << point_2;
output << point_3;
}
// Unit Test # 6: POINT class normal constructor (using both valid and invalid function inputs), POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_6(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 6: POINT class normal constructor (using both valid and invalid function inputs), POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point_0 = POINT(-1000, -999);";
output << "\nPOINT point_1 = POINT(999, 1000);";
output << "\noutput << point_0;";
output << "\noutput << point_1;";
POINT point_0 = POINT(-1000, -999);
POINT point_1 = POINT(999, 1000);
output << point_0;
output << point_1;
}
// Unit Test # 7: POINT class normal constructor, POINT class copy constructor, POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_7(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 7: POINT class normal constructor, POINT class copy constructor, POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point_0 = POINT(333, -666);";
output << "\nPOINT point_1 = POINT(point_0);";
output << "\noutput << point_0;";
output << "\noutput << point_1;";
POINT point_0 = POINT(333, -666);
POINT point_1 = POINT(point_0);
output << point_0;
output << point_1;
}
// Unit Test # 8: POINT class normal constructor, POINT class distance getter method, POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_8(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 8: POINT class normal constructor, POINT class distance getter method, POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point_0 = POINT(1, 1);";
output << "\nPOINT point_1 = POINT(-1, -1);";
output << "\noutput << point_0;";
output << "\noutput << point_1;";
POINT point_0 = POINT(1, 1);
POINT point_1 = POINT(-1, -1);
output << point_0;
output << point_1;
output << "\npoint_0.get_distance_from(point_1) = " << point_0.get_distance_from(point_1) << ".";
output << "\npoint_1.get_distance_from(point_0) = " << point_1.get_distance_from(point_0) << ".";
output << "\npoint_0.get_distance_from(point_0) = " << point_0.get_distance_from(point_0) << ".";
output << "\npoint_1.get_distance_from(point_1) = " << point_1.get_distance_from(point_1) << ".";
}
// Unit Test # 9: POINT class normal constructor, POINT class distance getter method, POINT class slope getter method, POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_9(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 9: POINT class normal constructor, POINT class distance getter method, POINT class slope getter method, POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point_0 = POINT(0, 4);";
output << "\nPOINT point_1 = POINT(3, 0);";
output << "\nPOINT point_2 = POINT(0, 0);";
output << "\noutput << point_0;";
output << "\noutput << point_1;";
output << "\noutput << point_2;";
POINT point_0 = POINT(0, 4);
POINT point_1 = POINT(3, 0);
POINT point_2 = POINT(0, 0);
output << point_0;
output << point_1;
output << "\npoint_0.get_distance_from(point_1) = " << point_0.get_distance_from(point_1) << ".";
output << "\npoint_1.get_distance_from(point_2) = " << point_1.get_distance_from(point_2) << ".";
output << "\npoint_2.get_distance_from(point_0) = " << point_2.get_distance_from(point_0) << ".";
output << "\npoint_0.get_slope_of_line_to(point_1) = " << point_0.get_slope_of_line_to(point_1) << ".";
output << "\npoint_1.get_slope_of_line_to(point_2) = " << point_1.get_slope_of_line_to(point_2) << ".";
output << "\npoint_2.get_slope_of_line_to(point_0) = " << point_2.get_slope_of_line_to(point_0) << ".";
}
// Unit Test # 10: POINT class normal constructor, POINT class data attribute getter methods, POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_10(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 10: POINT class normal constructor, POINT class data attribute getter methods, POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point = POINT(33.3, 88.8);";
output << "\noutput << point;";
POINT point = POINT(33.3, 88.8);
output << point;
output << "\npoint.get_X() = " << point.get_X() << ".";
output << "\npoint.get_Y() = " << point.get_Y() << ".";
}
// Unit Test # 11: POINT class normal constructor, POINT class distance getter method, POINT class slope getter method, POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_11(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 11: POINT class normal constructor, POINT class distance getter method, POINT class slope getter method, POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point = POINT(-1, 1);";
output << "\noutput << point;";
POINT point = POINT(-1, 1);
output << point;
output << "\npoint.get_distance_from(point) = " << point.get_distance_from(point) << ". // point refers to exactly one object";
output << "\npoint.get_slope_of_line_to(point) = " << point.get_slope_of_line_to(point) << ". // point refers to exactly one object";
}
// Unit Test # 12: POINT class normal constructor, POINT class setter methods, POINT class overloaded ostream operator method, and POINT class destructor.
void unit_test_12(std::ostream & output)
{
output << "\n\n--------------------------------------------------------------------------------------------------";
output << "\nUnit Test # 12: POINT class normal constructor, POINT class setter methods, POINT class overloaded ostream operator method, and POINT class destructor.";
output << "\n--------------------------------------------------------------------------------------------------";
output << "\nPOINT point = POINT(3, 3);";
output << "\noutput << point;";
POINT point = POINT(3, 3);
output << point;
output << "\nbool status = point.set_X(-1000);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
bool status = point.set_X(-1000);
output << std::endl << status << std::endl;
output << point;
output << "\nstatus = point.set_X(-999);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
status = point.set_X(-999);
output << std::endl << status << std::endl;
output << point;
output << "\nstatus = point.set_Y(-1000);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
status = point.set_Y(-1000);
output << std::endl << status << std::endl;
output << point;
output << "\nstatus = point.set_Y(-999);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
status = point.set_Y(-999);
output << std::endl << status << std::endl;
output << point;
output << "\nstatus = point.set_X(1000);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
status = point.set_X(1000);
output << std::endl << status << std::endl;
output << point;
output << "\nstatus = point.set_X(999);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
status = point.set_X(999);
output << std::endl << status << std::endl;
output << point;
output << "\nstatus = point.set_Y(1000);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
status = point.set_Y(1000);
output << std::endl << status << std::endl;
output << point;
output << "\nstatus = point.set_Y(999);";
output << "\noutput << std::endl << status << std::endl;";
output << "\noutput << point;";
status = point.set_Y(999);
output << std::endl << status << std::endl;
output << point;
}
/** program entry point */
int main()
{
// Declare a file output stream object.
std::ofstream file;
/**
* Set the number of digits of floating point numbers which are printed to the command line to 50.
* Set the number of digits of floating point numbers which are printed to the file output stream to 50.
*/
std::cout.precision(50);
file.precision(50);
/**
* If point_driver_output.txt does not already exist in the same directory as point_driver.cpp,
* then create a new file named point_driver_output.txt.
*
* Then open the plain-text file named point_driver_output.txt
* and set that file to be overwritten with program data.
*/
file.open("point_driver_output.txt");
// Print an opening message to the command line terminal.
std::cout << "\n\n--------------------------------";
std::cout << "\nStart Of Program";
std::cout << "\n--------------------------------";
// Print an opening message to the file output stream.
file << "--------------------------------";
file << "\nStart Of Program";
file << "\n--------------------------------";
/**
* Run each one of the unit test functions for this program.
*
* Call each unit test function twice such that the first function call prints text results to the command line terminal
* and the second function call prints text results to the output file stream.
*/
unit_test_0(std::cout);
unit_test_0(file);
unit_test_1(std::cout);
unit_test_1(file);
unit_test_2(std::cout);
unit_test_2(file);
unit_test_3(std::cout);
unit_test_3(file);
unit_test_4(std::cout);
unit_test_4(file);
unit_test_5(std::cout);
unit_test_5(file);
unit_test_6(std::cout);
unit_test_6(file);
unit_test_7(std::cout);
unit_test_7(file);
unit_test_8(std::cout);
unit_test_8(file);
unit_test_9(std::cout);
unit_test_9(file);
unit_test_10(std::cout);
unit_test_10(file);
unit_test_11(std::cout);
unit_test_11(file);
unit_test_12(std::cout);
unit_test_12(file);
// Print a closing message to the command line terminal.
std::cout << "\n\n--------------------------------";
std::cout << "\nEnd Of Program";
std::cout << "\n--------------------------------\n\n";
// Print a closing message to the file output stream.
file << "\n\n--------------------------------";
file << "\nEnd Of Program";
file << "\n--------------------------------";
// Close the file output stream.
file.close();
// Exit the program.
return 0;
}