-
Notifications
You must be signed in to change notification settings - Fork 0
/
058.rkt
61 lines (50 loc) · 1.76 KB
/
058.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#lang htdp/bsl
; Exercise 58.
; ------------
; Introduce constant definitions that separate the intervals for low prices and
; luxury prices from the others so that the legislators in Tax Land can easily
; raise the taxes even more.
; ------------------------------------------------------------------------------
#|
+-------------------------------------------+
| The Design Recipe Card |
|-------------------------------------------|
| From Problem Analysis to Data Definitions |
| Signature, Purpose Statement, Header |
| Functional Examples | + One example per clause + bounds
| Function Template | + One cond clause per clause
| Function Definition |
| Testing |
+-------------------------------------------+
|#
; A Price falls into one of three intervals:
; — 0 through 1000
; — 1000 through 10000
; — 10000 and above.
; interpretation the price of an item
; Price -> Number
; computes the amount of tax charged for p
#;
(define (sales-tax p) 0)
#|
| 0 | 537 | 1000 | 1282 | 10000 | 12017 |
|---+-----+------+------+-------+-------|
| 0 | 0 | 50 | 64 | 800 | 961 |
|#
(check-expect (sales-tax 537) 0)
(check-expect (sales-tax 1000) (* 0.05 1000))
(check-expect (sales-tax 12017) (* 0.08 12017))
(check-expect (sales-tax 0) 0)
(check-expect (sales-tax 1282) (* 0.05 1282))
(check-expect (sales-tax 10000) (* 0.08 10000))
(check-expect (sales-tax 12017) (* 0.08 12017))
(define (sales-tax-temp p)
(cond
[(and (<= 0 p) (< p 1000)) ...]
[(and (<= 1000 p) (< p 10000)) ...]
[(>= p 10000) ...]))
(define (sales-tax p)
(cond
[(and (<= 0 p) (< p 1000)) 0]
[(and (<= 1000 p) (< p 10000)) (* 0.05 p)]
[(>= p 10000) (* 0.08 p)]))