-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.cpp
More file actions
42 lines (35 loc) · 736 Bytes
/
13.cpp
File metadata and controls
42 lines (35 loc) · 736 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
#include <iostream>
using namespace std;
class c_polygon {
public:
virtual float area() {
return 0;
}
};
class c_rectangle : public c_polygon {
private:
float width, height;
public:
c_rectangle(float w, float h) : width(w), height(h) {}
float area() {
return width * height;
}
};
class c_triangle : public c_polygon {
private:
float base, height;
public:
c_triangle(float b, float h) : base(b), height(h) {}
float area() {
return 0.5 * base * height;
}
};
int main() {
c_polygon* p;
c_rectangle rect(4, 5);
c_triangle tri(3, 4);
p = ▭
cout<<"Rectangle Area: "<<p->area()<<endl;
p = &tri;
cout<<"Triangle Area: "<<p->area()<<endl;
}