Make sure you start your file with:
#lang htdp/bsl
Be sure to follow the Design Recipe and write test cases for each function. When you need to use \(\pi\), just use the built-in constant named pi.
Also, whenever your expected answer is an inexact number, DrRacket won’t let you use check-expect. Because inexact numbers always have a “fudge factor,” you have to tell DrRacket how close the answers should be to be counted correct. In those cases, you have to use the function check-within. It consumes three values: the function call you’re checking, what you expect the answer to be, and how close the two numbers should be to one another.
Here are some examples that use check-within and \(\pi\):
(check-within (area-of-circle 1) pi 0.000001) (check-within (area-of-circle 2) (* 4 pi) 0.000001) (check-within (area-of-circle 5) (* 25 pi) 0.000001)
Here are some formulas you may need:
Write the functions below, making sure to follow the Design Recipe. You can put all of them in the same file, just skip a line or two between functions.
volume-of-right-rectangular-prism, which consumes the length, width, and height of a rectangular solid and produces the volume. Write test cases for dimensions 2 by 3 by 7, 3.5 by 4 by 8, and 6 by 8 by 10.total-surface-area-of-right-cylinder which consumes the radius and height of a cylinder and produces its total surface area. Test it for a cylinder with radius 3 and height 4, another with radius 5 and height 2, and finally one with radius 5 and height 6.perimeter-of-regular-polygon. It consumes the number of sides in a polygon and the length of each side and produces the perimeter. Test it for a square with side length 3, a hexagon with side length 7, and a dodecagon with side length 15.lateral-area-of-regular-pyramid which consumes the number of sides the pyramid has, the length of each side, and the pyramid’s slant height. (Note that \(P\) in the formula for area is the perimeter of the base.) Test it for a three-sided pyramid where each side is 7 and the slant height is 10, a five-sided pyramid where each side is 3 and the slant height is 2, and a thirteen-sided pyramid where each side is 7 and the slant height is 23.slope. It consumes the \(x\) and \(y\) coordinates of two points and figures out the slope of the line connecting them. You may assume that the line is not vertical, so the slope will be defined. (Try your function with a vertical line in the Interactions window, just to see what happens.)triangle-area that uses the formula to find the area of a triangle.total-profit. It consumes the number of customers who buy tickets for a show, and produces how much income the theater makes for that show.sum-coins. It consumes four numbers: the number of pennies, nickels, dimes, and quarters in the bag; it produces the amount of money in the bag.