Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Use the concept of function override in C++ and create a function shape_area, which will calculate area

+3 votes
asked Jul 7, 2019 by anonymous
Use the concept of function override in C++ and create a function shape_area, which will calculate area of square, rectangle and a triangle. Override of the function should be controlled using the number of variables. In the main function you should demonstrate examples for all three cases of the shapes.

1 Answer

+1 vote
answered Aug 6, 2025 by Jerry Jeremiah (2,040 points)
Here is how you define the functions.  Now you just need to write the main function.

double shape_area(double a) { return a * a; }
// now that we have defined this we can't make one for:
// - a circle that takes a radius

double shape_area(double a, double b) { return a * b; }
// now that we have defined this we can't make one for:
// - a triangle that takes a base and a height
// - an ellipse that takes a major axis and a minor axis

double shape_area(double a, double b, double c) {
    double s = (a + b + c) / 2.0;
    return sqrt(s * (s - a) * (s - b) * (s - c));
}
// now that we have defined this we can't make one for:
// - any other calculation that takes three inputs
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...