;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname 16.6.1) (read-case-sensitive #t) (teachpacks ((lib "testing.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "testing.ss" "teachpack" "htdp"))))) ; Worked exercise 16.6.1 ; An employee has three parts: name, id, and salary. ; The name is a string, while id and salary are numbers. (define-struct employee (name id salary)) ; make-employee : string(name) number(id) number(salary) -> employee ; employee-name : employee -> string ; employee-id : employee -> number ; employee-salary : employee -> number ; employee? : object -> boolean #| (define (function-on-employee emp) ; emp an employee ; (employee-name emp) a string ; (employee-id emp) a number ; (employee-salary emp) a number ) |# ; change-salary : employee number -> employee (define (change-salary emp new-salary) ; emp an employee (make-employee "Joe" 352 65000) ; (employee-name emp) a string "Joe" ; (employee-id emp) a number 352 ; (employee-salary emp) a number 65000 ; new-salary a number 66000 ; desired answer an employee (make-employee "Joe" 352 66000) (make-employee (employee-name emp) (employee-id emp) new-salary) ) (check-expect (change-salary (make-employee "Joe" 352 65000) 66000) (make-employee "Joe" 352 66000)) (check-expect (change-salary (make-employee "Croesus" 2 197000) 1.49) (make-employee "Croesus" 2 1.49)) (generate-report)