-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASSI-4.cpp
64 lines (63 loc) · 1.21 KB
/
ASSI-4.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
61
62
63
64
#include <iostream>
using namespace std;
class Shape{
double a, b;
public:
void get_data(double x, double y) {
a = x;
b = y;
}
double get_a() {
return a;
}
double get_b() {
return b;
}
virtual void display_area() = 0;
};
class Triangle: public Shape {
public:
void display_area() {
cout << "Area of triangle: " << 0.5 * get_a() * get_b() << endl;
}
};
class Rectangle: public Shape {
public:
void display_area() {
cout << "Area of rectangle: " << get_a() * get_b() << endl;
}
};
class Circle: public Shape {
public:
void display_area() {
cout << "Area of circle: " << 3.14 * get_a() * get_a() << endl;
}
};
int main()
{
Shape *shape;
Triangle triangle;
double base, height;
cout << "Enter base and altitude: ";
cin >> base >> height;
shape = ▵
shape->get_data(base, height);
shape->display_area();
cout << endl;
Rectangle rectangle;
double length, breadth;
cout << "Enter length and breadth: ";
cin >> length >> breadth;
shape = &rectangle;
shape->get_data(length, breadth);
shape->display_area();
cout << endl;
Circle circle;
double radius;
cout << "Enter the radius: ";
cin >> radius;
shape = &circle;
shape->get_data(radius, 0);
shape->display_area();
return 0;
}