forked from LifeofAGeek/cpp-DS-Algo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoops1.cpp
More file actions
66 lines (55 loc) · 1.14 KB
/
oops1.cpp
File metadata and controls
66 lines (55 loc) · 1.14 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
66
#include<iostream>
using namespace std;
class Rectangle
{
private:
float length;
float breadth;
public:
//constructor overloading
Rectangle() //non-parametrized constructor
{
length=0;
breadth=0;
}
Rectangle(float l=0, float b=0) //parametrized constructor
{
length=l;
breadth=b;
}
Rectangle(Rectangle &rect) //copy constructor
{
length=rect.length;
breadth=rect.breadth;
}
float area()
{
return length*breadth;
}
float perimeter()
{
return 2*(length+breadth);
}
void setLengthBreadth(float l, float b) //accessors
{
length=l;
breadth=b;
}
float getlength() //mutators
{
return length;
}
float getBreadth()
{
return breadth;
}
};
int main()
{
Rectangle r1(10,5);
Rectangle r2(r1);
//r1.setLengthBreadth(10,5);
cout<<"obj: r1"<<endl<<r1.getlength()<<endl<<r1.getBreadth()<<endl<<r1.area()<<endl<<r1.perimeter();
cout<<"obj: r2"<<endl<<r2.getlength()<<endl<<r2.getBreadth()<<endl<<r2.area()<<endl<<r2.perimeter();
return 0;
}