-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_basic.cpp
60 lines (55 loc) · 983 Bytes
/
class_basic.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
#include<iostream>
using namespace std;
// class rectangle{
// private:
// int length;
// int breadth;
// public:
// rectangle(int l,int b){
// length=l;
// breadth=b;
// }
// int area(){
// return length*breadth;
// }
// void changeLength(int l){
// length=l;
// cout<<"\nchanged length is: "<<length;
// }
// };
// int main(){
// rectangle r(10,20);
// cout<<r.area();
// r.changeLength(44);
// }
class rectangle{
private:
int length;
int breadth;
public:
rectangle(){length=breadth=1;};
rectangle(int l,int b);
int area();
int perimeter();
int getLength(){return length;};
void changeLength(int l){length=l;};
~rectangle();
};
rectangle::rectangle(int l,int b){
length=l;
breadth=b;
}
int rectangle::area(){
return length*breadth;
}
int rectangle::perimeter(){
return (2*(length+breadth));
}
rectangle::~rectangle(){};
int main(){
rectangle r(10,20);
cout<<r.area();
cout<<"\n"<<r.perimeter();
r.changeLength(44);
cout<<r.getLength();
}