Due: 11:59pm, Thursday, Sep 04, 2023
100 points
For all Racket assignments in this course, set the DrRacket Language to Intermediate Student with lambda (Language → Choose Language → Teaching Languages → How to Design Programs → Intermediate Student with Lambda). Your assignment will be tested using the specified language level. If you use a different language level, your code may not work when it is tested.
contains? that consumes a symbol and a list of symbols and determines whether or not the symbol occurs in the list.count-symbols that consumes a list of symbols and produces the number of items in the list.count-numbers that counts how many numbers are in a list of numbers. [Note: the function merely works on inputs that are lists of numbers; it may blow up on anything else].avg-price. It consumes a list of toy prices and computes the average price of a toy. The average is the total of all prices divided by the number of toys. Toy prices are numbers.avg-price easy. Do not use the Racket library other than primitives mentioned in Lectures 2 and 3.avg-price generates an error report as described in Guidance below. elim-exp to eliminate expensive toys. The function consumes a number, called mp (short for "maximum price") and a list of toy prices, called lotp, and produces a list of all those prices in lotp that are below or equal to mp. For example(check-expect (elim-exp 1.0 (list 2.95 .95 1.0 5) (list .95 1.0)) = #true
[10pts] Develop the function delete to eliminate specific toys from a list. The function consumes the name of a toy, called ty, and a list of names, called lon, and produces a list of names that contains all components of lon with the exception of ty. For example,
(check-expect (delete 'robot (list 'robot 'doll 'dress)) (list 'doll 'dress)) = #true
[30pts] A list can be used to represent a finite set. For example,
(list 'c 'o 'm 'p)represents the set of symbols {'c , 'o, 'm, 'p}. In such a representation, we assume all elements in the list are unique; there are no duplicates.
Develop the function power that consumes a list of symbols los (representing a set) and produces a list of list of symbols representing the power set (set of all subsets) of los. Hint: write an auxiliary function cons-all that consumes a symbol sym and a list of list of symbols lolos and inserts symbol sym at the front of each list in lolos.
For example,
(check-expect (cons-all 'a (list (list 'c) (list 'o) (list 'm) (list 'p))
(list (list 'a 'c) (list 'a 'o) (list 'a 'm) (list 'a 'p))) = #trueerror function takes a single argument, a string specifying the error message to report, not two arguments as described in the book. The DrRacket Help Desk correctly documents the Racket error function. We recommend using a string (text enclosed in double quotation marks) like "An empty list of toy prices is an illegal input." as the argument. You can test the error-throwing behavior of a function using the check-error operation which is documented in the DrRacket Help Desk.power);write the template for the function (trivial when no recursion is involved);
write the code for the function; and
include illustrative test cases for the function, using at least the examples you developed above.
![]()