Design Recipe One - Program Definitions

CONTRACT, PURPOSE, HEADER - Name of program, Input / Output
EXAMPLES - Function Calls (2 or more) with the estimated answer that YOU calculate.
BODY - Formula to calculate the answer using variable parameters in the header
TEST - Execute the program. Compare the computer answer to your estimate. Check logic.


SALARY
Gross Wages - Taxes = Net Pay

;;wage:  number number -> number
;;compute weekly wage given the number hours worked and the hourly rate
(define (wage hours hrRate)
(wage 20 10) = 200
(wage 40 10) = 400
(wage 5 47.25) = 250
  (* hours hrRate)
Interaction Window:
200
=
200
400
=
400
#i236.25
=
250
Definition Window:
;;wage:  number number -> number
;;compute weekly wage given the number hours worked and the hourly rate
(define (wage hours hrRate)
  (* hours hrRate))

(wage 20 10) = 200
(wage 40 10) = 400
(wage 5 47.25) = 250

;;tax:  number -> number
;;compute taxes taken out of a paycheck at a tax rate of 15%
(define TAXRATE .15)
(define (tax wages)
(tax 200) = 30
(tax 400) = 60
(tax 236.25) = 36
 (* wages TAXRATE)
Interaction Window:
#i30.0
=
30
#i60.0
=
60
#i35.4375
=
36
Definition Window:
;;tax:  number -> number
;;compute taxes taken out of a paycheck at a tax rate of 15%
(define TAXRATE .15)
(define (tax wages)
  (* wages TAXRATE))

(tax 200) = 30
(tax 400) = 60
(tax 236.25) = 36

;; taxed-wage : number -> number
;; computes the taxed-wage, given the number of hours worked
(define (taxed-wage hours hrRate)
(taxed-wage 20 10) = 170
(taxed-wage 40 10) = 340
(taxed-wage 5 47.25) = 200
 (- (wage hours hrRate)
     (tax (wage hours hrRate))
Interaction Window:
Welcome to DrScheme, 
version 100.
Language: Beginner.
#i170.0
=
170
#i340.0
=
340
#i200.8125
=
200
Definition Window:
(define (wage hours hrRate)
  (* hours hrRate))

(define TAXRATE .15)
(define (tax wages)
  (* wages TAXRATE))

;; taxed-wage : number -> number
;; computes the taxed-wage, given the number of hours worked
(define (taxed-wage hours hrRate)
  (- (wage hours hrRate)
     (tax (wage hours hrRate))))

(taxed-wage 20 10) = 170
(taxed-wage 40 10) = 340
(taxed-wage 5 47.25) = 200

Home
E-mail
Lessons