29 lines
704 B
C++
29 lines
704 B
C++
#include <cmath>
|
|
#include <iostream>
|
|
|
|
// Triangle
|
|
double area(double a, double b, double c) {
|
|
double s = (a + b + c) / 2;
|
|
return std::sqrt(s * (s - a) * (s - b) * (s - c));
|
|
}
|
|
|
|
// Rectangle
|
|
double area(double a, double b) { return a * b; }
|
|
|
|
// Circle
|
|
double area(double a) { return M_PI * a * a; }
|
|
|
|
int main() {
|
|
|
|
double a = 3, b = 4, c = 5;
|
|
|
|
std::cout << "Area of a triangle with sides " << a << ", " << b << " and "
|
|
<< c << ": " << area(a, b, c) << std::endl
|
|
<< "Area of rectangle with sides " << a << " and " << b << ": "
|
|
<< area(a, b) << std::endl
|
|
<< "Area of circle with radius " << a << ": " << area(a)
|
|
<< std::endl;
|
|
|
|
return 0;
|
|
}
|