-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program38.cpp
60 lines (49 loc) · 877 Bytes
/
Program38.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
/*PROGRAM USING ABSTRACT CLASS*/
#include <iostream>
using namespace std;
// Base class
class shape
{
public:
// pure virtual function providing interface framework
virtual int getarea() = 0;
void setlength(int l)
{
length = l;
}
void setbreadth(int b)
{
breadth = b;
}
protected:
int length;
int breadth;
};
// Derived Classes
class rectangle : public shape
{
public:
int getarea() override
{
return length * breadth;
}
};
class square : public shape
{
public:
int getarea() override
{
return length * length;
}
};
int main()
{
rectangle rect;
square sq;
rect.setlength(7);
rect.setbreadth(5);
cout << "Area of rectangle is: " << rect.getarea() << endl;
sq.setlength(5);
cout << "Area of square is: " << sq.getarea() << endl;
return 0;
}