Skip to main content

Posts

Showing posts with the label overloaded function calc_area()

write a program with an overloaded function calc_area() that calculates and returns area of circle and rectangle. Assume appropriate number and type of arguments and return type.

 Here's a program with an overloaded function calc_area() that calculates and returns the area of a circle and rectangle. The program assumes a radius and length/width are given as arguments for the circle and rectangle, respectively. The return type for both function is a "double". #include <iostream> using namespace std; const double PI= 3.14; double calc_area(double radius) {     return PI*radius*radius; } double calc_area(double length, double width) {     return length * width; } int main() {     double radius, length, width;     cout << "Enter the radius of the circle: ";     cin >> radius;     cout << "Enter the length of the rectangle: ";     cin >> length;     cout << "Enter the width of the rectangle: ";     cin >> width;     double circle_area = calc_area(radius);     double rectangle_area = calc_area(length, width); ...