//EXP NO.
1:- Design Simple Program to calculate the area of different shapes (Circle, Rectangle,
Triangle) using function overloading.
#include <iostream>
#include <cmath> // For M_PI
using namespace std;
// Function to calculate area of a Circle
float area(float radius) {
return M_PI * radius * radius;
// Function to calculate area of a Rectangle
float area(float length, float width) {
return length * width;
// Function to calculate area of a Triangle
float area(float base, float height, bool isTriangle) {
if (isTriangle)
return 0.5 * base * height;
else
return 0.0;
int main() {
float r, l, w, b, h;
// Circle
cout << "Enter radius of circle: ";
cin >> r;
cout << "Area of Circle = " << area(r) << endl;
// Rectangle
cout << "\nEnter length and width of rectangle: ";
cin >> l >> w;
cout << "Area of Rectangle = " << area(l, w) << endl;
// Triangle
cout << "\nEnter base and height of triangle: ";
cin >> b >> h;
cout << "Area of Triangle = " << area(b, h, true) << endl;
return 0;
//OUTPUT