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 necessary code for this homework is at
http://cis.udel.edu/~caputo/CISC280/labH_code.html
You can access it here

Homework exercises (Due at start of lab 16 April 01):

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 portion of the weekly sales that is determined by the salesperson's commission (which is a percentage similar to 0.1). 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.
    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, his overtime pay is 2 times his normal pay. Install this package and show test examples.