-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract_class.cpp
More file actions
51 lines (42 loc) · 822 Bytes
/
Copy pathAbstract_class.cpp
File metadata and controls
51 lines (42 loc) · 822 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
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
class shape
{
protected:
float d1,d2;
public:
void getdim()
{
cin>>d1>>d2;
}
virtual float area() = 0;
};
class triangle : public shape
{
public:
virtual float area()
{
return (0.5 * d1 * d2);
}
};
class rectangle : public shape
{
public:
virtual float area()
{
return (d1 * d2);
}
};
int main()
{
//shape s; -->ERROR as abstract class cannot have object
triangle t;
cout<<"\nEnter triangle's base and height : ";
t.getdim();
cout<<"Area of triangle = "<<t.area();
rectangle r;
cout<<"\n\nEnter rectangle's length and breadth : ";
r.getdim();
cout<<"Area of rectangle = "<<r.area();
}