Finger Exercises on Composing Functions

<#1630#>Exercise 3.3.1<#1630#> The United States uses the <#1632#>English<#1632#> system of (length) measurements. The rest of the world uses the <#1633#>metric<#1633#> system. So, people who travel abroad and companies that trade with foreign partners often need to convert English measurements to metric ones and <#1634#>vice versa<#1634#>. Here is a table that shows the six major units of length measurements of the English system:

#tabular1637#

Develop the functions <#70669#><#1654#>feet<#1654#><#60512#><#1655#><#1655#><#1656#>-;SPMgt;<#1656#><#1657#><#1657#><#60512#><#1658#>inches<#1658#><#70669#>, <#70670#><#1659#>yards<#1659#><#60513#><#1660#><#1660#><#1661#>-;SPMgt;<#1661#><#1662#><#1662#><#60513#><#1663#>inches<#1663#><#70670#>, <#70671#><#1664#>rods<#1664#><#60514#><#1665#><#1665#><#1666#>-;SPMgt;<#1666#><#1667#><#1667#><#60514#><#1668#>cm<#1668#><#70671#>, <#70672#><#1669#>furlongs<#1669#><#60515#><#1670#><#1670#><#1671#>-;SPMgt;<#1671#><#1672#><#1672#><#60515#><#1673#>cm<#1673#><#70672#>, and <#70673#><#1674#>miles<#1674#><#60516#><#1675#><#1675#><#1676#>-;SPMgt;<#1676#><#1677#><#1677#><#60516#><#1678#>inches<#1678#><#70673#>. Then develop the functions <#70674#><#1679#>inches<#1679#><#60517#><#1680#><#1680#><#1681#>-;SPMgt;<#1681#><#1682#><#1682#><#60517#><#1683#>cm<#1683#><#70674#>, <#70675#><#1684#>feet<#1684#><#60518#><#1685#><#1685#><#1686#>-;SPMgt;<#1686#><#1687#><#1687#><#60518#><#1688#>cm<#1688#><#70675#>, <#70676#><#1689#>yards<#1689#><#60519#><#1690#><#1690#><#1691#>-;SPMgt;<#1691#><#1692#><#1692#><#60519#><#1693#>cm<#1693#><#70676#>, <#70677#><#1694#>rods<#1694#><#60520#><#1695#><#1695#><#1696#>-;SPMgt;<#1696#><#1697#><#1697#><#60520#><#1698#>cm<#1698#><#70677#>, <#70678#><#1699#>furlongs<#1699#><#60521#><#1700#><#1700#><#1701#>-;SPMgt;<#1701#><#1702#><#1702#><#60521#><#1703#>cm<#1703#><#70678#>, and <#70679#><#1704#>miles<#1704#><#60522#><#1705#><#1705#><#1706#>-;SPMgt;<#1706#><#1707#><#1707#><#60522#><#1708#>cm<#1708#><#70679#>. <#1709#>Hint:<#1709#> Reuse functions as much as possible. Use variable definitions to specify constants.~ external Solution<#60523#><#60523#> <#1715#>Exercise 3.3.2<#1715#> Develop the program <#60524#><#1717#>volume-cylinder<#1717#><#60524#>. It consumes the radius of a cylinder's base disk and its height; it computes the volume of the cylinder.~ external Solution<#60525#><#60525#> <#1723#>Exercise 3.3.3<#1723#> Develop <#60526#><#1725#>area-cylinder<#1725#><#60526#>. The program consumes the radius of the cylinder's base disk and its height. Its result is the surface area of the cylinder.~ external Solution<#60527#><#60527#> <#1731#>Exercise 3.3.4<#1731#> Develop <#60528#><#1733#>area-pipe<#1733#><#60528#>, which computes the surface area of a pipe. A pipe is an open cylinder. The program consumes three values: the pipe's inner radius, its length, and the thickness of its wall. Develop two versions: a program that consists of a single definition and a program that consists of several function definitions. Which one invokes more confidence?~ external Solution<#60529#><#60529#> <#1739#>Exercise 3.3.5<#1739#> Develop the program <#60530#><#1741#>height<#1741#><#60530#>, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of #tex2html_wrap_inline72498# in <#60531#><#1742#>t<#1742#><#60531#> time units and a height of 1/2 * v * t where v is the speed at t.~ external Solution<#60532#><#60532#> <#1748#>Exercise 3.3.6<#1748#> Recall the program <#72146#><#70680#><#1750#>Fahrenheit<#1750#><#60533#><#1751#><#1751#><#1752#>-;SPMgt;<#1752#><#1753#><#1753#><#60533#><#1754#>Celsius<#1754#><#70680#><#72146#> from exercise~#exf2c#1755>. The program consumes a temperature measured in Fahrenheit and produces the Celsius equivalent. Develop the program <#72147#><#70681#><#1756#>Celsius<#1756#><#60534#><#1757#><#1757#><#1758#>-;SPMgt;<#1758#><#1759#><#1759#><#60534#><#1760#>Fahrenheit<#1760#><#70681#><#72147#>, which consumes a temperature measured in Celsius and produces the Fahrenheit equivalent. Now consider the function

<#70682#>;; <#60535#><#1765#>I<#1765#> <#1766#>:<#1766#> <#1767#>number<#1767#> <#1768#><#1768#><#1769#>-;SPMgt;<#1769#><#1770#><#1770#> <#1771#>number<#1771#><#60535#><#70682#>
<#1772#>;; to convert a Fahrenheit temperature to Celsius and back <#1772#> 
<#1773#>(d<#1773#><#1774#>efine<#1774#> <#1775#>(I<#1775#> <#1776#>f)<#1776#> 
  <#1777#>(<#1777#><#70683#><#1778#>Celsius<#1778#><#60536#><#1779#><#1779#><#1780#>-;SPMgt;<#1780#><#1781#><#1781#><#60536#><#1782#>Fahrenheit<#1782#><#70683#> <#1783#>(<#1783#><#70684#><#1784#>Fahrenheit<#1784#><#60537#><#1785#><#1785#><#1786#>-;SPMgt;<#1786#><#1787#><#1787#><#60537#><#1788#>Celsius<#1788#><#70684#> <#1789#>f)))<#1789#> 
Evaluate <#60538#><#1793#>(I<#1793#>\ <#1794#>32)<#1794#><#60538#> by hand and using DrScheme's stepper. What does this suggest about the composition of the two functions?~ external Solution<#60539#><#60539#>