Structure-related signatures in beginning student language in DrRacket

53 Views Asked by At

I have to write a program for the following task:

In a company, there are departments with associated sub-departments, which in turn can have sub-departments. Endless nesting is therefore possible. Each department has employees (number-of-employees). The total number of employees consists of the employees in the department and those in the sub-departments.

1.1 Write a definition for department with the number of employees and the sub-departments. All concepts known from the lecture may be used (especially list-of). Remember to define further data and structures if necessary. Write an example with 2 sub-departments.

1.2 Write a function sum-employee that calculates the number of all employees in the department and associated sub-departments. If necessary, write an auxiliary function to calculate the number of employees in the subdivisions. Write down the signature.

I tried to solve the problem in the following way. I program in Beginning Student Language (BSL) and may only use this to solve the task.

(define-struct department (number-of-employees sub-departments))
; a department is a struct
; interp. the number of employees and the sub-departments of each department


(define DepartmentSig (signature (DepartmentOf Number (ListOf DepartmentSig)))) 

(define department1 (make-department 10
                                     (list (make-department 50 empty)
                                           (make-department 100 empty)))) 

(: sum-employees (DepartmentSig -> Number))
; calculates the number of employees per department  
(check-expect (sum-employees department1) 160) 
(define (sum-employees department)
  (+ (department-number-of-employees department) (number-of-employees-sub-department (department-sub-departments department))))


(: number-of-employees-sub-department ((ListOf DepartmentSig) -> Number))
; calculates the number of employees per sub-department
(check-expect (number-of-employees-sub-department (department-sub-departments department1)) 150)
(define (number-of-employees-sub-department sub-departments)
  (if (empty? sub-departments) 0
      (+ (sum-employees (first sub-departments)) 
         (number-of-employees-sub-department (rest sub-departments)))))

I think that my signatures are wrong, because after evaluating the program I am told that there is a signature violation. How do I adjust my signatures so that they are suitable for the issue above?

0

There are 0 best solutions below