Homework Assignment #2
Due by 9:30AM, Thursday October 11th, 2001

Revised-- see italics below

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, squares, rectangle, circles, and cubes.

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) Triangles (2) Squares (3) Rectangles (4) Circles (5) Cubes

For example, a 1 is acceptable input to start the calculation for a triangle.

Assuming the user types in the correct number for a triangle, square, rectangle or circle, the user should then be given the option of calculating the area or the perimeter (known as circumference for a circle) of the shape. The user is to be asked to type 1 for the area, 2 for the perimeter or circumference).

If the user types the correct number for a cube, (s)he should be prompted to choose between the volume and the surface 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:

Triangle:

Area= .5 * base * height

Perimeter = 3 * Side (assume an equilateral triangle).

Square:

Area = side2

Perimeter = 4 * side

Rectangle:

Area = base * height

Perimeter = 2 * base + 2 * height

Circle:

Area = PI * radius2

Circumference = 2 * PI * radius

Cube:

Volume = side3

Surface Area = 6 * side2

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) Triangles (2) Squares (3) Rectangles (4) Circles (5) Cubes

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) Triangles (2) Squares (3) Rectangles (4) Circles (5) Cubes

5

Would you like to find the (1) Volume or (2) Surface Area?

1

Please type in the length of the side:

3

The volume is 27.00
 

SAMPLE RUN # 3

Welcome to the Shape Information Program!

Press the number in parentheses to calculate
information regarding one of the following shapes:

(1) Triangles (2) Squares (3) Rectangles (4) Circles (5) Cubes

4

Would you like to find the (1) Area or (2) Circumference?

2

Please type in the length of the radius:

5

The circumference is 31.40

Paste the source code inside an e-mail message to hm305@nyu.edu and include HW2 in the Subject Line of the e-mail message.