-
Notifications
You must be signed in to change notification settings - Fork 549
/
Copy path05_01.cpp
51 lines (45 loc) · 874 Bytes
/
05_01.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
#include <bits/stdc++.h>
using namespace std;
class Rectangle {
private:
double width;
double height;
public:
Rectangle() {
width = height = 0;
}
Rectangle(double width_, double height_) {
width = width_;
height = height_;
}
double ComputeArea() {
return width * height;
}
double ComputePerimeter() {
return 2 * (width + height);
}
// Setters & Getters
double GetHeight() {
return height;
}
void SetHeight(double height) {
this->height = height;
}
double GetWidth() {
return width;
}
void SetWidth(double width) {
this->width = width;
}
};
int main() {
Rectangle r1;
r1.SetWidth(5);
r1.SetHeight(10);
cout << r1.ComputeArea() << "\n"; // 50
Rectangle r2(10, 3);
cout << r2.ComputeArea() << "\n"; // 30
r2.SetWidth(0);
cout << r2.ComputeArea() << "\n"; // 0
return 0;
}