-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexersise_polymorphism.cpp
More file actions
64 lines (54 loc) · 1.03 KB
/
exersise_polymorphism.cpp
File metadata and controls
64 lines (54 loc) · 1.03 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
#include<bits/stdc++.h>
using namespace std;
class shape
{
public:
virtual float perimeter()=0;
virtual float area()=0;
};
class rectangle : public shape
{ private:
float length;
float breadth;
public:
rectangle(float l=1, float b=1)
{
length=l;
breadth=b;
}
float perimeter()
{
return 2*(length+breadth);
}
float area()
{
return length*breadth;
}
};
class circle :public shape
{ private:
float radius;
public:
circle(float r)
{
radius=r;
}
float perimeter()
{
return 2*3.14*radius;
}
float area()
{
return radius*radius*3.14;
}
};
int main()
{
shape *s=new rectangle(4,5);
cout<<"perimeter of rectangle is : "<<s->perimeter() << endl;
cout<<"area of rectangle is : "<<s->area()<<endl;
s=new circle(3);
cout<<"perimeter of circle is : "<<s->perimeter() << endl;
cout<<"area of circle is : "<<s->area();
return 0;
}