This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.cpp
86 lines (70 loc) · 1.71 KB
/
Rectangle.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
/*
* Ethan Reece - EDR220000
* Rajit Goel - RXG210046
*/
#include <iostream>
#include <math.h>
#include "Rectangle.h"
const float epsilon = 0.000001f;
Rectangle::Rectangle(double length, double width) {
this->length = length;
this->width = width;
}
Rectangle Rectangle::operator+(const Rectangle &rs) const {
Rectangle final;
final.length=length+rs.length;
final.width=width+rs.width;
return final;
}
Rectangle Rectangle::operator-(const Rectangle &rs) const {
Rectangle final;
final.length=length-rs.length;
if(final.length<0){
final.length=0;
}
final.width=width-rs.width;
if(final.width<0){
final.width=0;
}
return final;
}
bool Rectangle::operator<(const Rectangle &rs) const {
double lhs = length*width;
double rhs = rs.length*rs.width;
if(fabs(lhs-rhs)<epsilon){
return false;
}else if(lhs<rhs){
return true;
}else{
return false;
}
}
bool Rectangle::operator>(const Rectangle &rs) const {
double lhs = length * width;
double rhs = rs.length * rs.width;
if (fabs(lhs - rhs) < epsilon) {
return false;
} else if (lhs > rhs) {
return true;
} else {
return false;
}
}
std::ostream &operator<<(std::ostream &output, const Rectangle &rectangle) {
output << "length: " << rectangle.length << ", width: " << rectangle.width;
return output;
}
Rectangle::Rectangle(const Rectangle &rectangle) {
length = rectangle.length;
width = rectangle.width;
}
Rectangle &Rectangle::operator++() {
length++;
width++;
return *this;
}
Rectangle Rectangle::operator++(int) {
auto oldRectangle = new Rectangle(*this);
++*this;
return *oldRectangle;
}