home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / p2_14bs.seq < prev    next >
Text File  |  1990-03-29  |  2KB  |  57 lines

  1. \ Comp 462
  2. \ Balraj Sidhu   Set: 14D4
  3. \ Date: March 29, 1990
  4. \ Problem 2.14  -- Table of surface area and volume of a tank (part a)
  5.  
  6. : tank_area ( l w h -- )
  7.         3dup 5 roll * 2 * -rot * 2 * + -rot * 2 * + ;
  8.  
  9. : .one ( n -- )
  10.         9 spaces                         \ Indent table entry
  11.         dup 8 .r                         \ print number
  12.         dup dup dup tank_area 12 .r      \ print area of tank
  13.         dup dup * * 13 .r ;              \ print volume of tank
  14.  
  15. : .heading ( -- -- )
  16.         cr cr
  17.         cr 14 spaces ." SIDE    SURFACE AREA    VOLUME "
  18.         cr 14 spaces ." feet    Square feet   cubic feet "
  19.         cr 14 spaces ." ====    ============  ========== " ;
  20.  
  21. : .cubical_table ( first last --- )
  22.         .heading
  23.         1+ swap
  24.         ?do cr i .one loop
  25.         cr cr ;
  26.  
  27. \ Proble 2.14 -- Part b
  28. \ Spherical tank
  29.  
  30. : *pi ( n -- n*pi )
  31.         355 113 */ ;
  32.  
  33. : sptank_volume ( l w h -- )
  34.         4 *pi * * * 3 / ;
  35.  
  36. : sptank_area
  37.         * 4 * *pi ;
  38.  
  39. : .print ( n -- )
  40.         9 spaces                         \ Indent table entry
  41.         dup 8 .r                         \ print number
  42.         dup dup sptank_area 12 .r        \ print area of tank
  43.         dup dup sptank_volume 13 .r ;    \ print volume of tank
  44.  
  45. : .heading2 ( -- -- )
  46.         cr cr
  47.         cr 14 spaces ." RADIUS  SURFACE AREA    VOLUME "
  48.         cr 14 spaces ." ======  ============  ========== " ;
  49.  
  50. : .spherical_table ( first last --- )
  51.         .heading2
  52.         1+ swap
  53.         ?do cr i .print loop
  54.         cr cr ;
  55.  
  56.  
  57.