0% found this document useful (0 votes)
6 views2 pages

Exp No1

The document presents a C++ program that calculates the area of different shapes: Circle, Rectangle, and Triangle using function overloading. It defines three overloaded functions named 'area' to compute the area based on the parameters provided. The main function prompts the user for dimensions and displays the calculated areas for each shape.

Uploaded by

gholapatharv36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Exp No1

The document presents a C++ program that calculates the area of different shapes: Circle, Rectangle, and Triangle using function overloading. It defines three overloaded functions named 'area' to compute the area based on the parameters provided. The main function prompts the user for dimensions and displays the calculated areas for each shape.

Uploaded by

gholapatharv36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

//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

You might also like