-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (52 loc) · 1.28 KB
/
main.cpp
File metadata and controls
70 lines (52 loc) · 1.28 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
67
68
69
70
#include<iostream>
using namespace std;
class Shape
{
public:
virtual int area()=0;
virtual int perimeter()=0;
};
class Rectangle : public Shape
{
public:
int length;
int breadth;
Rectangle(int len,int bread){length=len;breadth=bread;}
int area(){return length*breadth;}
int perimeter(){return (2*(length+breadth));}
friend ostream & operator<<(ostream &out,Rectangle &r);
};
ostream & operator<<(ostream &out,Rectangle &r)
{
out<<"Length = "<<r.length<<"Breadth = "<<r.breadth;
return out;
}
class Circle : public Shape
{
public:
int radius;
Circle(int rad){radius=rad;}
int area(){return (3.145*radius*radius);}
int perimeter(){return (2*3.145*radius);}
friend ostream & operator<<(ostream &out,Circle &c);
};
ostream & operator<<(ostream &out,Circle &c)
{
out<<"Radius = "<<c.radius;
return out;
}
int main()
{
Shape *s;
Rectangle r(10,5);
s=&r;
cout<<"area of Rectangle = "<<s->area()<<endl;
cout<<"perimeter of Rectangle = "<<s->perimeter()<<endl;
cout<<r<<endl;
Circle c(10);
s=&c;
cout<<"Area of Circle = "<<s->area()<<endl;
cout<<"Perimeter of Circle = "<<s->perimeter()<<endl;
cout<<c;
return 0;
}