Blame


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