Files
ooplab/lab1/2.cpp
Amneesh Singh ad185c994e labs 1-6: init
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2022-12-24 14:03:08 +05:30

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;
}