Created
October 18, 2016 17:36
-
-
Save TuxCoding/3e5348adb38051969724ed92968dd2e8 to your computer and use it in GitHub Desktop.
First Racket program to calculate the content size of a ring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; area-of-ring: number number -> number | |
| ;; Determines the area of a ring | |
| ;; with outer radius outer and an inner radius inner | |
| ;; Example: (area-of-ring 5 3) is | |
| ;; roughly 50.26544 | |
| (define (area-of-ring outer inner) | |
| (- (area-of-circle outer) | |
| (area-of-circle inner))) | |
| ;;Tests | |
| (check-expect (area-of-ring 0 0) 0) | |
| (check-within (area-of-ring 5 5) 0 0.0001) | |
| (check-within (area-of-ring 5 3) 50.26544 0.001) | |
| ;; area-of-circle: number -> number | |
| ;; Determines the area of a circle with a radius radius | |
| ;; Example: (area-of-circle 1) is pi (3.14159) | |
| (define (area-of-circle radius) | |
| (* radius radius pi)) | |
| ;; Tests | |
| (check-expect (area-of-circle 0) 0) | |
| (check-within (area-of-circle 4) (* 16 pi) 0.0001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment