Monday, 3 October 2011

Sample Algorithm



Problem summary:
Design an interactive program to read the height and radius of the base of a cone. The program should compute the surface area and volume of the cone. As output it should display the input values and the computed results. Assume that the formulas for computing surface area and volume have been provided elsewhere.

Required Constant: PI = 3.14159

Required Variables (all double):
  height, radius
  area, circum, volume, slant_ht, surf_area

ALGORITHM:
prompt for and read height of cone
prompt for and read radius of base of cone

   area = PI * radius * radius   //
compute area of base of cone
   circum = 2.0 * PI * radius    //
compute circumference of base of cone
   volume = 1.0/3.0 * area * height    //
compute volume of cone
   slant_ht = sqrt(radius*radius + height*height)   //
compute slant height
   surf_area = area + 1./2.* circum * slant_ht    //
compute surface area of cone

print radius, height, volume, and surf_area with appropriate labels