A program is required to allow students to calculate the volume of a number of standard three-dimensional shapes. It will use functions to allow other shapes to be added in the future.
Cuboid
volume = base × depth × height
Triangular prism
volume = ½ × base × depth × height
Sphere
volume = 4/3 × Pi × radius × radius × radius
Pi is a constant with value 3.142
Write a program that meets the following requirements:
- Output a menu to ask the user for an input to indicate the shape for which a volume needs to be calculated, from the three shapes given or if they want to stop the program. The program must validate the input.
- Input the data needed to calculate the volume of the chosen shape, based on the given formulae.
- Create one function for each shape to calculate and return the volume using the given formulae. Each function uses the input data as parameters.
- Output the volume in the main program, rounded to two decimal places.
The program continues until the user inputs the stop option from the menu.
You must use pseudocode or program code and add comments to explain how your code works.
All variables and constants used must be declared for this algorithm.
All inputs and outputs must contain suitable messages.