Your program should first display instructions and the following menu (color is just for highlighting):
Welcome to the Shape Information Program!
Press the number in parentheses to calculate
information regarding one of the following shapes:
(1) Right Triangle (2) Equilateral Triangle (3) Rectangle (4) Cube (5) Sphere
For example, a 1 is acceptable input to start the calculation for a right triangle.
Assuming the user types in the correct number for a triangle or rectangle, the user should then be given the option of calculating the area or the perimeter of the shape. The user is to be asked to type 1 for the area, 2 for the perimeter.
If the user types the correct number for a cube, (s)he should be prompted to choose between the volume and the surfhce area. The user is to be asked to type 1 for volume and 2 for surface area.
Have the program error handle all invalid numbers by displaying the message, "The number [<the specific number entered>] is an invalid choice: program will terminate, " and then end the program. Be sure to have the computer display the bad number within the error message.
See "Notes and Hints" below for additional requirements.
The formulae are as follows:
Right Triangle:
Area= .5 * base * height:
Perimeter = base + height + hypothenuse
hypothenuse = sqrt(base^{2} + height^{2})
Equilateral Triangle:
Area= .25 * side^{2} * sqrt(3)
Perimeter = 3 * side
Recta2gle:
Area = base * height
Perimeter = 2 * base + 2 * height
Cube:
Volume = side^{3}
Surface Area = 6 * side^{2}
Sphere:
Volume = (4/3) * PI * radius^{3}
Surface Area = 4 * PI * ratius^{2}
Notes & Hints:
- You must create and use a constant for PI (3.14).
- You must create AND use constants for the different options to select (for each shape, area, perimeter, volume, and surface area). For example: #define SELECTION_RIGHT_TRIANGLE 1
- You must use a switch statement for the selection of the geometric shapes, and if statements for choosing between the next 2 options (area and perimeter for triangles and rectangles, and volume and surface area for cubes and spheres).
- Use cases in the switch to handle each valid number for selecting shapes and if statements for the particular information to calculate.
- Only use the variables relevant for the proper execution. (Your program shouldn't use a radius variable when computing information regarding triangles, etc.).
- Have the program display all answers to TWO decimal places.
- Remember about integer division in C. If you want to obtain a result of a true mathematical division, you need to make sure at least one of operands is a floating point number.
SAMPLE RUN # 1
Welcome to the Shape Information Program!
Press the number in parentheses to calculate
information regarding one of the following shapes:
(1) Right Triangle (2) Equilateral Triangle (3) Rectangle (4) Cube (5) Sphere
3
Would you like to find the (1) Area or (2) Perimeter?
1
Please type in the length of the base and height:
2.5 1.3
The area is 3.25
SAMPLE RUN # 2
Welcome to the Shape Information Program!
Press the number in parentheses to calculate
information regarding one of the following shapes:
(1) Right Triangle (2) Equilateral Triangle (3) Rectangle (4) Cube (5) Sphere
5
Would you like to find the (1) Volume or (2) Surface Area?
1
Please type in the radious of the sphere:
3
The volume is
113.04
SAMPLE RUN # 3
Welcome to the Shape Information Program!
Press the number in parentheses to calculate
information regarding one of the following shapes:
(1) Right Triangle (2) Equilateral Triangle (3) Rectangle (4) Cube (5) Sphere
4
Would you like to find the (1) Volume or (2) Surface Area?
2
Please type in the length of the cube side:
5
The surface area
is 150.00
Good luck!