-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathq-9.cpp
60 lines (55 loc) · 1.04 KB
/
q-9.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 Shape
{
public: double a,b,r;
void get_data1()
{
cin>>r;
}
void get_data2()
{
cin>>a>>b;
}
virtual void display_area () = 0;
};
class Circle:public Shape
{
public: void display_area ()
{
cout<<"Area of Circle = "<<3.14*r*r<<endl;
}
};
class Triangle:public Shape
{
public: void display_area ()
{
cout<<"Area of triangle = "<<0.5*a*b<<endl;
}
};
class Rectangle:public Shape
{
public: void display_area ()
{
cout<<"Area of rectangle = "<<a*b<<endl;
}
};
int main()
{
Circle c;
Shape *sc = &c;
cout<<"Enter radius of the circle: ";
sc->get_data1();
sc->display_area();
Triangle t;
Shape *st = &t;
cout<<"Enter base and altitude: ";
st->get_data2();
st->display_area();
Rectangle R;
Shape *sR = &R;
cout<<"Enter length and breadth: ";
sR->get_data2();
sR->display_area();
return 0;
}