Skip to main content

Posts

Showing posts with the label Write a program with an overloaded function calcArea() that calculate and return area of circle

Write a program with an overloaded function calcArea() that calculate and return area of circle, rectangle and triangle. Assume appropriate number and type of arguments and return type.

 Here's a C++ program that defines an overloaded function called calcArea() that calculates and returns the area of a circle, rectangle, or triangle based on the parameters passed to it: #include <iostream> #include <cmath> const double PI = 3.14159; double calcArea(double radius) {     return PI * pow(radius, 2); } double calcArea(double width, double height) {     return width * height; } double calcArea(double base, double height, bool isTriangle) {     if (isTriangle) {         return 0.5 * base * height;     } else {         return -1; // Invalid input for rectangle     } } int main() {     double radius = 5.0;     double width = 10.0;     double height = 8.0;     double base = 6.0;     cout << "Area of circle with radius " << radius << " = " << calcArea(radius) << endl;     cout <<...