-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog14.cpp
More file actions
46 lines (35 loc) · 956 Bytes
/
prog14.cpp
File metadata and controls
46 lines (35 loc) · 956 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
/*
Write a C++ Program to compute the area of a circle, triangle and rectangle
using function overloading.
*/
#include <cmath>
#include <iostream>
using namespace std;
class Shape {
public:
float area(float r) { return M_PI * pow(r, 2); }
float area(float l, float w) { return l * w; }
double area(float a, float b, float c) {
double s = (a + b + c) / 2;
double x = s * (s - a) * (s - b) * (s - c);
return sqrt(x);
}
};
int main() {
float r, l, w, a, b, c;
Shape s;
cout << "Enter radius: ";
cin >> r;
cout << "Area of Circle: " << s.area(r) << endl;
cout << "Enter length and width" << endl;
cin >> l >> w;
cout << "Area of Rectangle: " << s.area(l, w) << endl;
cout << "Enter three sides (Triangle)" << endl;
cin >> a >> b >> c;
if (a + b > c && a + c > b && b + c > a) {
cout << "Area of Triangle: " << s.area(a, b, c) << endl;
} else {
cout << "Invalid triangle" << endl;
}
return 0;
}