26.6k views
2 votes
Write a programm. to calculate the

area of circle,rectangle and triangle
using function overloading.

User Peter Baer
by
7.7k points

1 Answer

3 votes

#include <iostream>

using namespace std;

// Function to calculate area of circle

double area(double radius) {

return 3.14 * radius * radius;

}

// Function to calculate area of rectangle

double area(double length, double breadth) {

return length * breadth;

}

// Function to calculate area of triangle

// Renamed to avoid redefinition

double areaTriangle(double base, double height) {

return 0.5 * base * height;

}

int main() {

double radius = 5.5;

double length = 10.5, breadth = 5.0;

double base = 10.0, height = 8.0;

// Call function to calculate area of circle

cout << "Area of circle: " << area(radius) << endl;

// Call function to calculate area of rectangle

cout << "Area of rectangle: " << area(length, breadth) << endl;

// Call function to calculate area of triangle

cout << "Area of triangle: " << areaTriangle(base, height) << endl;

return 0;

}

User SeparateReality
by
7.9k points

Related questions

asked Aug 7, 2021 46.7k views
Yixuan asked Aug 7, 2021
by Yixuan
8.5k points
1 answer
0 votes
46.7k views
asked Jan 8, 2021 191k views
Haein asked Jan 8, 2021
by Haein
7.9k points
1 answer
2 votes
191k views