-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq49.cpp
47 lines (40 loc) · 1.04 KB
/
q49.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
#include <iostream>
using namespace std;
class Shape {
public:
virtual float area() = 0;
};
class Rectangle : public Shape {
float length, breadth;
public:
Rectangle(float length, float breadth) : length(length), breadth(breadth) { }
float area() {
return length * breadth;
}
float get_length() {
return length;
}
float get_breadth() {
return breadth;
}
};
class Circle: public Shape {
float radius;
public:
Circle(float r) : radius(r) {}
float area() {
return 3.14 * radius * radius;
}
float get_radius() {
return radius;
}
};
int main() {
Rectangle rect(25, 10);
Circle circ(7);
cout << "Rectangle dimensions: " << rect.get_length() << "x" << rect.get_breadth() << '\n';
cout << "Rectangle area: " << rect.area() << "\n\n";
cout << "Circle radius: " << circ.get_radius() << '\n';
cout << "Circle area: " << circ.area() << '\n';
return 0;
}