;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname 3.3.2-3.3.4) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "convert.ss" "teachpack" "htdp")))))
(define PI 3.14)
;; area-of-circle : number -> number
;; Computes the area of the circle given the radius
(define (area-of-circle radius)
(* PI (sqr radius)))
;; area-of-ring : number number -> number
;; Computes the area of a ring given the inner and outer radii.
;; It does so by subtracting the area of the inner circle from the outer circle.
(define (area-of-ring inner outer)
(- (area-of-circle outer) (area-of-circle inner)))
;; volume-cylinder : number number -> number
;; Computes the volume of a cylinder given the radius and height.
;; It does so by multiplying the area of the base by the height.
(define (volume-cylinder radius height)
(* (area-of-circle radius) height))
;; lateral-surface-area : number number -> number
;; Computes the lateral surface area of a cylinder given the radius and height (the circumference times the height)
(define (lateral-surface-area radius height)
(* 2 PI radius height))
;; area-cylinder : number number -> number
;; Computes the surface area of a cylinder given the radius and height
;; It does so by adding 2 times the area of the base by the lateral surface area.
(define (area-cylinder radius height)
(+
(* 2 (area-of-circle radius))
(lateral-surface-area radius height)))
;; area-pipe : number number number -> number
;; Computes the surface area of a pipe given its inner radii, thickness, and height.
;; It does so by finding the lateral surface area of the outer shell and the inner shell and adding this to two times the surface area of either the top or bottom ring.
(define (area-pipe inner thick height)
(+
(lateral-surface-area (+ inner thick) height)
(lateral-surface-area inner height)
(* 2 (area-of-ring inner (+ inner thick)))))
;; area-pipe2 : number number number -> number
;; Computes the surface area of a pipe according the the following formula
;; A = 2*PI*(inner+thick)*height)+(2*PI*inner*height)+2*PI*((inner+thick)^2-inner^2)
(define (area-pipe2 inner thick height)
(+
(* 2 PI (+ inner thick) height)
(* 2 PI inner height)
(* 2 PI
(- (sqr (+ inner thick)) (sqr inner)))))