-
Notifications
You must be signed in to change notification settings - Fork 0
/
rect.cpp
78 lines (73 loc) · 1.74 KB
/
rect.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
#include<iostream>
using namespace std;
class Rectangle{
public:
int width;
int length;
int area;
int perimeter;
Rectangle(int width, int length){
this->width = width;
this->length = length;
area = width*length;
perimeter = (width+length)*2;
}
friend ostream& operator<<(ostream& tpel, Rectangle rect){
tpel<<"Length: "<<rect.length<<endl;
tpel<<"Width: "<<rect.width<<endl;
tpel<<"Area: "<<rect.area<<endl;
tpel<<"Perimeter: "<<rect.perimeter<<endl;
return tpel;
}
};
template <class T>
class Comparator{
virtual int hamematel(T a, T b){
if(a > b){
return 1;
}else if(a < b){
return -1;
}
return 0;
}
};
class SortByArea : public Comparator<Rectangle>{
int compare(Rectangle a, Rectangle b){
if(a.area > b.area){
return 1;
}else if(a.area < b.area){
return -1;
}
return 0;
}
};
class SortByPerimeter : public Comparator<Rectangle>{
int compare(Rectangle a, Rectangle b){
if(a.perimeter > b.perimeter){
return 1;
}else if(a.perimeter < b.perimeter){
return -1;
}
return 0;
}
};
class SortByWidth : public Comparator<Rectangle>{
int compare(Rectangle a, Rectangle b){
if(a.width > b.width){
return 1;
}else if(a.width < b.width){
return -1;
}
return 0;
}
};
class SortByLength : public Comparator<Rectangle>{
int compare(Rectangle a, Rectangle b){
if(a.length > b.length){
return 1;
}else if(a.length < b.length){
return -1;
}
return 0;
}
};