# Draft Homework 1

**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.- Carefully follow the
**Sample Solution to a Programming Problem**in the**Racket HW Guide**. Only half of the credit for each programming problem is based on the correctness of your code as determined by our test cases. Much of the grade is based on how well you follow the*design recipe*. For a crisp example of an ideal solution, look at the**Sample Solution to a Programming Problem**that sorts**list-of-number**at the end of**Sample Solution to a Programming Problem**in the**Racket HW Guide**. This process may appear painful but it shows "in the small" how program design should be done "in the large". It is not difficult. If you carefully inspect the sample program (notably the commenting), it shows the level of documentation of your program*design*that we expect.

**Do the following programming problems using only the primitives mentioned in Lectures 2 and****3. Do not use the functions in the Racket library if they are not mentioned in Lectures 2 and 3.**- [10 pts] Develop the function
that consumes a symbol and a list of symbols and determines whether or not the symbol occurs in the list.`contains?`

- [10 pts] Develop the function
that consumes a list of symbols and produces the number of items in the list.`count-symbols`

- [10 pts] Develop the function

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].**count-numbers** - [20 pts] Develop the function
. 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`

**Hints:**- Develop one or more auxiliary functions (following the design recipe for each auxiliary function) to make the definition of
easy. Do not use the Racket library other than primitives mentioned in Lectures 2 and 3.`avg-price`

- If the list of toy prices is empty, the function
generates an error report as described in Guidance below.`avg-price`

- Develop one or more auxiliary functions (following the design recipe for each auxiliary function) to make the definition of
- [10pts] Develop the function
to eliminate expensive toys. The function consumes a number, called`elim-exp`

(short for "maximum price") and a list of toy prices, called**mp**, and produces a list of all those prices in`lotp`

that are below or equal to`lotp`

. For example`mp`

(check-expect (elim-exp 1.0 (list 2.95 .95 1.0 5) (list .95 1.0)) = #true

[10pts] Develop the function

to eliminate specific toys from a list. The function consumes the name of a toy, called`delete`

, and a list of names, called`ty`

, and produces a list of names that contains all components of`lon`

with the exception of`lon`

`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

that consumes a list of symbols`power`

(representing a set) and produces a list of list of symbols representing the power set (set of all subsets) of`los`

.`los`

**Hint:**write an auxiliary functionthat consumes a symbol`cons-all`

and a list of list of symbols**sym**and inserts symbol`lolos`

at the front of each list in`sym`

**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)))`

`= #true`

- [10 pts] Develop the function

**Guidance:**- Follow the design recipe imitating
**Sample Solution to a Programming Problem**in the**Racket HW Guide**. - Problem 4 asks you to write a function that checks for the empty list as an input error and reports an aborting error in the case. (The purpose statement should document this behavior!) In DrRacket, the
function takes a single argument, a string specifying the error message to report,`error`

*not two arguments*as described in the book. The DrRacket Help Desk correctly documents the Racketfunction. We recommend using a string (text enclosed in double quotation marks) like`error`

as the argument. You can test the error-throwing behavior of a function using the`"An empty list of toy prices is an illegal input."`

operation which is documented in the DrRacket Help Desk.`check-error`

- Study Figure 26 in Section 9.4 of the book for a more detailed description of the design recipe and how it should be documented in the program text that you develop.
- To follow the design recipe, you must:
- write the
*type contract*and*purpose*(behavioral contract); - provide at least 3 well-chosen examples (more for complex functions like
);`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.

- write the

- Follow the design recipe imitating

- Carefully follow the