-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path09_rectangle.cpp
executable file
·88 lines (67 loc) · 1.3 KB
/
09_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
87
88
#include <iostream>
using namespace std;
class Rectangle{
float l, w;
public:
void setlength(float);
void setwidth(float);
float perimeter();
float area();
void show();
int sameArea(Rectangle);
};
int main(){
Rectangle r1, r2;
r1.setlength(5);
r1.setwidth(2.5);
r2.setlength(5);
r2.setwidth(18.9);
r1.show();
cout<<"Area : "<<r1.area();
cout<<"\nPerimeter : "<<r1.perimeter()<<"\n";
r2.show();
cout<<"Area : "<<r2.area();
cout<<"\nPerimeter : "<<r2.perimeter()<<"\n";
if(r1.sameArea(r2)){
cout<<"Same area\n";
}else{
cout<<"Not same area\n";
}
r1.setlength(15);
r1.setwidth(6.3);
r1.show();
cout<<"Area : "<<r1.area();
cout<<"\nPerimeter : "<<r1.perimeter()<<"\n";
r2.show();
cout<<"Area : "<<r2.area();
cout<<"\nPerimeter : "<<r2.perimeter()<<"\n";
if(r1.sameArea(r2)){
cout<<"Same area\n";
}else{
cout<<"Not same area\n";
}
return 0;
}
// Rectangle
void Rectangle::setlength(float length){
l = length;
}
void Rectangle::setwidth(float width){
w = width;
}
float Rectangle::perimeter(){
return 2*(l+w);
}
float Rectangle::area(){
return l*w;
}
void Rectangle::show(){
cout<<"\nLength : "<<l;
cout<<"\nWidth : "<<w<<"\n";
}
int Rectangle::sameArea(Rectangle R){
float area, Rarea;
area = l * w;
Rarea = R.l * R.w;
return (area == Rarea)?1:0;
}