Page 172 - Learn To Program With Scratch
P. 172

y  − y
                                                           slope, m  =  2  1
                                                                  x 2  − x 1
                                                           y-intercept,  b  = y 1  − mx 1

                                                           Round m and b to the nearest
                                                           hundredths.


                         Figure 6-29: The Compute procedure

                             The ShowEquation procedure is shown in Figure 6-30. It uses two
                         variables (term1 and term2) and two subprocedures to properly format
                         the equation for display.































                         Figure 6-30: The ShowEquation procedure

                             The ShowEquation procedure considers the following special cases
                         while formatting the line equation:

                         •   If the slope is 1, term1 will be set to x (instead of 1x).
                         •   If the slope is –1, term1 will be set to –x (instead of –1x).
                         •   term2 is formed using the proper sign (plus or minus) of the y-intercept.
                         •   If the y-intercept is 0, the equation will have the form y = mx.






           150   Chapter 6
                                           www.it-ebooks.info
   167   168   169   170   171   172   173   174   175   176   177