-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_basic.cpp
More file actions
49 lines (41 loc) · 792 Bytes
/
1_basic.cpp
File metadata and controls
49 lines (41 loc) · 792 Bytes
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
#include <iostream>
using namespace std;
class Rect{
private:
int length;
int breadth;
public:
Rect(){
length= breadth=1;
}
Rect(int l, int b);
int area();
int perimeter();
int getLength() { //get is an accessor function
return length;
}
void setLength(int l){ //set is a mutator function
length= l;
}
~Rect(){
cout<<"Destructor"<<endl;
}
};
//using scope resolution
Rect:: Rect(int l, int b){
length=l;
breadth=b;
}
int Rect:: area(){
return length*breadth;
}
int Rect:: perimeter(){
return 2*(length+breadth);
}
int main()
{
Rect r(10,5);
cout<<"Area "<<r.area()<<endl;
cout<<"Perimeter "<<r.perimeter()<<endl;
return 0;
}