-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathq6.cpp
More file actions
55 lines (51 loc) · 729 Bytes
/
q6.cpp
File metadata and controls
55 lines (51 loc) · 729 Bytes
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
#include <iostream>
using namespace std;
class c_polygon
{
protected:
int width, height;
public:
void init_poly(int a,int b)
{
width = a;
height = b;
}
virtual int area()
{
return 0;
}
};
class rectangle: public c_polygon
{
public:
int area()
{
return width * height;
}
};
class triangle: public c_polygon
{
public:
int area()
{
return width * height / 2;
}
};
int main()
{
rectangle r;
triangle t;
c_polygon *p;
int x,y;
cout<<"enter length and breadth of rectangle:";
cin>>x>>y;
p=&r;
p->init_poly(x,y);
cout<<"area of rectangle:"<<p->area()<<endl;
cout<<"enter base and height of triangle:";
cin>>x>>y;
p=&t;
p->init_poly(x,y);
cout<<"area of triangle:"<<p->area()<<endl;
return 0;
}