Lab Module H -- Data-Directed Programming

CISC 280 Program Development Techniques

Purpose:
  1. To learn some basic concepts of data-directed programming.
  2. To gain further understanding of data abstraction.
Goals:
  1. To write procedures that use data-directed programming.

Reading: SICP (Structure and Interpretation of Computer Programs), Section 2.4 (especially section 2.4.3)

The dispatch table code needed for this homework is available for download here or, on the composers, you can do (load "~saunders/280/table.scm").

Homework exercises (Due at start of lab 15 April 02):

Big Corporation USA has two departments - a sales department and graphics department.

  1. Exercise 1
    In the graphics department, each payroll record contains information about the employee's hourly pay rate, number of hours worked this week, and amount of overtime hours. Each record is identified by the employee's SSN (social security number). Create a constructor and selectors for the payroll department.

  2. Exercise 2
    Write a function for the graphics department that takes an employee record and calculates the pay for the week. To do this, you should know that an employee gets his regular pay rate for regular hours worked and time-and-a-half (1.5 times the regular pay rate) for overtime worked. Be sure to use your abstract data types created in exercise 1.

  3. Exercise 3
    In the sales department, each employee record includes the salesperson's SSN, total sales for the week, commission rate, and weekly salary. Create constructors and selectors for the sales department.

  4. Exercise 4
    Write a function for the sales department that takes a salesperson record as input, and computes the pay for this week. To do this, you should know that a salesperson gets her weekly salary each week, plus a commission which is the weekly sales times the commission rate. For example, if a salesperson's weekly sales are $2300 and her commission rate is .03 (3 percent), then the commission that week is $69. Be sure to use your abstract data types created in exercise 3.

  5. Exercise 5
    Put all this together into two packages install-graphics-employee-package and install-sales-employee-package. To get full credit you must install the two packages and show examples that give the correct results.
    These install- procedures use the put and get dispatch table operations. See pages 181-183 for examples. Do (load "~saunders/280/table.scm") to have the dispatch table. Example;
    (define e1 (make-graphics-employee 123456789 12 40 3))
    (define e2 (make-sales-employee 987654321 4560 0.1 350))
    (SSN e1)
    123456789
    (pay e2)
    806.0
    

  6. Exercise 6
    Write a procedure print-payroll that takes a list of employee records, and prints out the pay for each employee on a line by itself.
    Example:
    (define e1 (make-graphics-employee 123456789 12 40 3))
    (define e2 (make-sales-employee 987654321 4560 0.1 350))
    (define list-of-employees (list e1 e2))
    
    (print-payroll list-of-employees)
    123456789 $534.0
    987654321 $806.0
    
    

    Flourishes (these are optional problems):

  7. Add another employee package named manager. It should include SSN, rate, hours, overtime, and which department he is the manager of (sales or graphics). Also, the overtime pay rate is 2 times the normal pay rate. Install this package and show test examples.