V22.0002 - ASSIGNMENT 2

Just when you thought it was safe to forget geometry, your boss asks you to write a program that will compute various information regarding triangles, rectangles, cubes and spheres.

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(base2 + height2)

Equilateral Triangle:

Area= .25 * side2 * sqrt(3)

Perimeter = 3 * side

Recta2gle:

Area = base * height

Perimeter = 2 * base + 2 * height

Cube:

Volume = side3

Surface Area = 6 * side2

Sphere:

Volume = (4/3) * PI * radius3

Surface Area = 4 * PI * ratius2

Notes & Hints:

For example, the following would be a valid execution of the program (the blue is displayed by the computer, and the red represents the user's input):


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!