       ͻ
        Lesson 2 Part 070  F-PC 3.5 Tutorial by Jack Brown 
       ͼ

                  Ŀ
                    Lots of Problems! 
                  
ķ
  Problem 2.10  
Ľ
  Tank volume and surface area.
  Write words  .LWH   VOLUME   and  AREA  along the lines
  of the previous problem except that they take 3 stack items,
  length, width, and height.  VOLUME computes the volume of the
  tank. AREA computes the surface area of the tank.  Combine
  these into a single word   TANK  which performs the function
  of all three as in PROBLEM - 2.1.

ķ
 Problem  2.11  
Ľ
  Rectangle  again.
  The area and perimeter of a rectangle       -----------(X2,Y2)
  can be determined from the coordinates      |         |
  of either pair of opposite corners.         |         |
  A = ( X2 - X1 )*( Y2 - Y1)                  |         |
  P = 2*(( X2 - X1 )+( Y2 - Y1))              -----------
                                           (X1,Y1)
  Write words to find the length, width, area, and perimeter
  and then combine them into one one word as in problem 1.
  Can any of the work from problem 1 be used here?
  Do your words work if you feed them upper left and lower
  right coordinates?

ķ
 Problem 2.12  
Ľ
  Falling objects.
  The height of a falling object above the ground at time t
  seconds is given by
           height =  h0 - v0*t - 16*t*t
  where h0 is the initial height in feet
  and v0 is the initial velocity in feet per second.
  Write a word called   HEIGHT that takes initial height
  initial velocity and a time from the stack and produces the
  following output.
  You type:     1000 100 3  HEIGHT     ( return )
  And see :     Initial height is 1000 feet.
                Initial velocity is 100 feet per second.
                Height after  3  seconds is 412  feet.
  Does your solution consist of one long definition?
  If it does factor it as we did for TANK_VOLUME
    ( the 412 above may be wrong!! )


ķ
 Problem 2.13   
Ľ
Find the error in the program below.
\  DISPLAYING A TABLE    contains error!!!     09:57JWB01/17/86
\   New word:    .R   ( n w   -- )
\   Print  n  right justified in a field  w  wide.
: .ONE  ( n   -- )
        12 SPACES               \ Indent table entry.
        DUP 8 .R                \ Print number.
        DUP DUP *  8 .R         \ Print square of number.
    DUP DUP DUP  * *  8 .R ;    \ Print cube of number.
: .HEADING  ( -- )
       CR CR CR 14 SPACES
       ." NUMBER  SQUARE    CUBE" ;
: .TABLE  ( first last -- )
        .HEADING             \  ?ENOUGH   explain it.
        1+ SWAP
        ?DO CR I .ONE LOOP
        CR CR ;
\ *** Hint: .TABLE leaves garbage on the stack. Use Debug to
\ *** find where and fix it so it won't do it any more!

ķ
 Problem 2.14  
Ľ
Make your own Tank Table Program.
a)Modify the previous example so that it gives a table of
  volumes and surface areas of cubical tanks. Note: CUBICAL!!!
  The new heading should have the form:

        SIDE    SURFACE AREA     VOLUME
        feet    square feet    cubic feet
        ====    ============   ==========

  Entries should be neatly centered under the table headings!!

b)Repeat the above problem for spherical tanks.  Heading
  should read:  RADIUS    SURFACE AREA     VOLUME   etc.

  For a sphere   V = 4 pi R*R*R/3
                 S = 4 pi R*R
                pi = 3.1416
  Hint:  to multiply by pi see Brodie or use -
  : *PI  ( n -- n*pi )   355 113  */  ;

ķ
 Problem 2.15  
Ľ
  What does this program do?

: .ONE  ( n -- )
        12 SPACES DUP EMIT DUP 4 .R
        HEX 4 .R DECIMAL ;
: .HEADING  ( -- )
       CR CR CR 9 SPACES ." CHAR DEC HEX"  ;
: ATABLE  ( first last -- )
        .HEADING
        1+ 256 MIN   SWAP  0 MAX
        ?DO CR I .ONE LOOP ;
: .TABLE  ( -- )
        16 0 DO  I 16 * DUP 15 +
                 ATABLE  KEY  DROP
             LOOP ;

Ŀ
  Please move to Lesson 2 Part 080  

