-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.cpp
More file actions
65 lines (50 loc) · 1.03 KB
/
Rectangle.cpp
File metadata and controls
65 lines (50 loc) · 1.03 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
#include <iostream>
using namespace std;
class Rectangle {
private:
int length;
int width;
public:
// Constructor
Rectangle(int l = 0, int w = 0) {
length = l;
width = w;
}
// Setters
void setLength(int l) {
length = l;
}
void setWidth(int w) {
width = w;
}
void set(int l, int w) { // set both length and width
length = l;
width = w;
}
// Getters
int getLength() {
return length;
}
int getWidth() {
return width;
}
// Area
int calculate_area() {
return length * width;
}
int calculate_perimeter() {
return 2 * (length + width);
}
void display() {
cout << "Length: " << length << ", Width: " << width << endl;
cout << "Area: " << calculate_area() << endl;
cout << "Perimeter: " << calculate_perimeter() << endl << endl;
}
};
int main() {
Rectangle r1(2, 3), r2;
r2.set(5, 6);
r1.display();
r2.display();
return 0;
}