Lecture notes for the Introduction to Computer Science for non-majors by James Tam Return to the course web page

Geometry calculator

Write a geometry program that will calculate the following formulas: the area of a circle, and the are and volume of a sphere.  The program will be menu operated with three options

(c)ircle: calculate the area.
(s)phere: calculate the area and volume
(q)uit: to end the program.

Circle:
The area of the circle is calculated as follows:
circleArea = PI * radius * radius.
and PI is 3.141592654.
 

Sphere:
The sphere calculations are as follows:
sphereSurfaceArea =  4 * PI * radius * radius
sphereVolume =  4/3 * PI * radius *  radius * radius

Quit:

Unless this option is selected the program will continue displaying the above menu options.  When the user does decide to quit the program a brief message should be displayed indicating that the program is now ending.