-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArea_of_shapes.cpp
70 lines (68 loc) · 1 KB
/
Area_of_shapes.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
61
62
63
64
65
66
67
68
69
70
#include<iostream>
using namespace std;
class shape
{
protected:
double a,b;
public:
void getdata()
{
a=b=0;
}
virtual void showarea()=0;
};
class triangle : public shape
{
public:
void getdata()
{
cout<<"\nEnter sides of triangle\n";
cin>>a>>b;
}
virtual void showarea()
{
cout<<"Area is "<<(0.5*a*b);
}
};
class rectangle : public shape
{
public:
void getdata()
{
cout<<"Enter sides of rectangle\n";
cin>>a>>b;
}
virtual void showarea()
{
cout<<"Area is "<<a*b;
}
};
class circle : public shape
{
private:
int r;
public:
void getdata()
{
cout<<"\nEnter radius\n";
a=b=0;
cin>>r;
cout<<"Area is : "<<(3.14*r*r);
}
virtual void showarea()
{
circle::getdata();
}
};
int main()
{
rectangle r;
triangle t;
circle c1;
r.getdata();
r.showarea();
t.getdata();
t.showarea();
c1.getdata();
return 0;
}