Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.2.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
4 ;An employee is a structure
5 ;(make-employee name ssn rate)
6 ;where name is a symbol and ssn and rate are numbers.
7 ;
8 ;Work is a structure
9 ;(make-work name hours)
10 ;where name is a symbol and hours is a number.
11 ;
12 (define-struct employee (name ssn rate))
13 (define-struct work (name hours))
14 ;
15 ;A list-of-employees is either
16 ;1. empty or
17 ;2. (cons e loe)
18 ;where e is a employee structure and loe is a list-of-employees.
20 ;A list-of-work is either
21 ;1. empty or
22 ;2. (cons w low)
23 ;where w is a work structure and low is a list-of-work.
25 ;
26 ;Template
27 ;fun-for-employee : employee -> ???
28 ;(define (fun-for-employee an-employee)
29 ; ... (employee-name an-employee) ...
30 ; ... (employee-ssn an-employee) ...
31 ; ... (employee-rate an-employee) ...)
32 ;
33 ;fun-for-work : work -> ???
34 ;(define (fun-for-work a-work)
35 ; ... (work-name a-work) ...
36 ; ... (work-hours a-work) ...)
38 ;fun-for-loe-low : loe low -> ???
39 ;(define (fun-for-loe-low loe low)
40 ; (cond
41 ; [(empty? loe) ...]
42 ; [(cons? loe)
43 ; ... (employee-rate (first loe)) ...
44 ; ... (work-hours (first low)) ...
45 ; ... (fun-for-loe-low (rest loe) (rest low)) ...]))
47 ;A list-of-numbers is either
48 ;1. empty or
49 ;2. (cons n lon)
50 ;where n is a number and lon is a list-of-numbers.
51 ;
52 ;Template
53 ;fun-for-2lon : lon lon -> ???
54 ;(define (fun-for-2lon lon1 lon2)
55 ; (cond
56 ; [(empty? lon1) ...]
57 ; [(cons? lon1) ... (first lon1) (first lon2) ...
58 ; ... (fun-for-lon (rest lon1) (rest lon2)) ...]))
59 ;
60 ;hours->wages : lon lon -> number
61 ;Given hours and rate, both list-of-numbers, compute the wages and return it as a list-of-numbers.
63 (define (hours->wages hours rate)
64 (cond
65 [(empty? hours) empty]
66 [(cons? hours) (cons (* (first hours) (first rate))
67 (hours->wages (rest hours) (rest rate)))]))
68 (define list1 '(4 5 6 7 8 9 10))
69 (define list2 '(8.5 2.5 5.5 6.5 7.5 4.5 3.5))
71 ;employees-and-work->wages : loe low -> number
72 (define (employees-and-work->wages loe low)
73 (cond
74 [(empty? loe) empty]
75 [(cons? loe)
76 (cons (* (employee-rate (first loe))
77 (work-hours (first low)))
78 (employees-and-work->wages (rest loe) (rest low)))]))
80 (define loe1 (list (make-employee 'Mark 621 13.50)
81 (make-employee 'Zack 345 18.50)
82 (make-employee 'Ronald 224 9.50)))
83 (define low1 (list (make-work 'Mark 30)
84 (make-work 'Zack 60)
85 (make-work 'Ronald 55)))