![]() |
VOOZH | about |
Given the dimensions of the 3D Shapes like Cube, Cuboid, or Cylinder, the task is to find the volume of all the 3D Shapes using function overloading.
Examples:
Input: Cube: L = 3, Cuboid: L = 3, B = 4, H = 3, Cylinder: R = 2, H = 7
Output:
Volume of Cube: 27
Volume of Cuboid: 36
Volume of Cylinder: 176Input: Cube: L = 2, Cuboid: L = 3, B = 2, H = 3, Cylinder: R = 1, H = 7
Output:
Volume of Cube: 8
Volume of Cuboid: 18
Volume of Cylinder: 22
Approach: The given problem can be solved by creating the different functions having the same name, say Volume but different function definitions. For each shape and then overload all the functions by passing different parameters to them and then call all the functions from the main function with the help of switch-case statements.
Below is the C++ program to find the volume of the different 3D shapes using function overloading:
Output:
Time complexity: O(1)
Auxiliary Space: O(1)