-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle_Main.cpp
More file actions
130 lines (106 loc) · 3.12 KB
/
Rectangle_Main.cpp
File metadata and controls
130 lines (106 loc) · 3.12 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
#include "Rectangle.h"
static void test01_ctors()
{
using namespace Rectangles;
Rectangle rect1;
rect1.print();
Rectangle rect2(3, 3, 5, 5);
rect2.print();
Rectangle rect3(3, 3, 5, 1);
rect3.print();
Rectangle rect4(3, 3, 1, 1);
rect4.print();
Rectangle rect5(3, 3, 1, 5);
rect5.print();
}
static void test02_methods()
{
using namespace Rectangles;
Rectangle rect(3, 4, 9, 10);
rect.print();
std::cout << "Circumference: " << rect.circumference() << std::endl;
std::cout << "Diagonal: " << rect.diagonal() << std::endl;
std::cout << "Area: " << rect.area() << std::endl;
std::cout << "IsSquare: " << rect.isSquare() << std::endl;
}
static void test03_center()
{
using namespace Rectangles;
Rectangle rect1(1, 3, 3, 1);
rect1.print();
Point p = rect1.center();
std::cout << "Center: (" << p.getX() << "," << p.getY() << ')' << std::endl;
Rectangle rect2(1, 4, 4, 1);
rect2.print();
p = rect2.center();
std::cout << "Center: (" << p.getX() << "," << p.getY() << ')' << std::endl;
}
static void test04_move()
{
using namespace Rectangles;
Rectangle rect(1, 1, 4, 5);
rect.print();
rect.moveTo(5, -5);
rect.print();
}
static void test05_intersection()
{
using namespace Rectangles;
Rectangle center(30, 30, 10, 10);
Rectangle upperLeft(10, 10, 10, 10);
Rectangle upperRight(50, 10, 10, 10);
Rectangle lowerLeft(10, 50, 10, 10);
Rectangle lowerRight(50, 50, 10, 10);
Rectangle intersection;
intersection = center.intersection(upperLeft);
intersection.print();
intersection = center.intersection(upperRight);
intersection.print();
intersection = center.intersection(lowerLeft);
intersection.print();
intersection = center.intersection(lowerRight);
intersection.print();
}
static void test06_intersection()
{
using namespace Rectangles;
Rectangle center(20, 20, 30, 30);
Rectangle upperLeft(10, 10, 20, 20);
Rectangle upperRight(40, 10, 20, 20);
Rectangle lowerLeft(10, 40, 20, 20);
Rectangle lowerRight(40, 40, 20, 20);
Rectangle intersection;
intersection = center.intersection(upperLeft);
intersection.print();
intersection = center.intersection(upperRight);
intersection.print();
intersection = center.intersection(lowerLeft);
intersection.print();
intersection = center.intersection(lowerRight);
intersection.print();
}
static void test07_equals()
{
using namespace Rectangles;
Rectangle rect1(1, 1, 4, 5);
Rectangle rect2(1, 1, 4, 5);
bool equals = rect1.equals(rect2);
std::cout << equals << std::endl;
rect2.setX(10);
equals = rect1.equals(rect2);
std::cout << equals << std::endl;
}
void exerciseRectangle()
{
using namespace Rectangles;
test01_ctors();
test02_methods();
test03_center();
test04_move();
test05_intersection();
test06_intersection();
test07_equals();
}
// ===========================================================================
// End-of-File
// ===========================================================================