Question: ( define LOC 0 empty ) ( define - struct course ( number credits dependents ) ) ;;James, pls check below Course instances are correct,

(define LOC0 empty)
(define-struct course (number credits dependents))
;;James, pls check below Course instances are correct, 22 Course number is defined.
(define C100(make-course 1003 LOC0))
(define C210(make-course 2104'(C110)))
(define C213(make-course 2134'(C210)))
(define C221(make-course 2214'(C210)))
(define C313(make-course 3133'(C213 C221)))
(define C317(make-course 3173'(C213 C221)))
;define list of all course in natural numer
(define list-of-course (list 100210213221313317))
;define tree-list in course numer
(define tree-list (list C100 C210 C213 C221 C313 C317))
;; helper function to extract course numbers from a single course
(define (all-course-numbers--course course)
(list (course-number course)))
;; produce a list of all course numbers in the given tree
(define (all-course-numbers tree)
(cond
[(empty? tree) empty]
[(course? tree)(all-course-numbers--course tree)]
[(list? tree)(all-course-numbers--loc tree)]
[else (error "Invalid input")]))
;; helper function to extract course numbers from a list of courses
(define (all-course-numbers--loc loc)
(apply append (map all-course-numbers loc)))
(define (courses-w-credits c credits)
;; Produce a list of courses and their dependents with credits >= specified credits
(cond [(>=(course-credits c) credits)
(cons c (courses-w-credits--loc (course-dependents c) credits))]
[else
(courses-w-credits--loc (course-dependents c) credits)]))
(define (courses-w-credits--loc loc credits)
;; Helper function to process a list of courses and their dependents with credits >= specified credits
(cond [(empty? loc) empty]
[else
(append (courses-w-credits (first loc) credits)
(courses-w-credits--loc (rest loc) credits))]))
This program snippet doesn't run well for problem 2 and 3 below
(@problem 2)
;;
;; Design a function that produces the list of all the course numbers in the
;; course's tree including the given course's number.
;;
;; Your @htdf tag and the rest of the design MUST have the definition for
;; the function that takes Course as an argument first. The function that
;; operates on a list must be second. Marks will only be rewarded for
;; solutions that order the design this way.
;;
(@problem 3)
;;
;; Design a function that takes two arguments: a Course and a Natural, in that
;; order. It produces the list of courses in the tree that are worth that
;; many credits or more.
;;
;; Your @htdf tag and the rest of the design MUST have the definition for
;; the function that takes Course as an argument first. The function that
;; operates on a list must be second. Marks will only be rewarded for
;; solutions that order the design this way.
;;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!