Assignment 5a
Due Date: Monday at 9:00pm (Week 5)
Purpose Further practice with lists.
Exercise 1 Work through section 9.1, and do HtDP Exercise 140
Exercise 2 Work through section 9.3, and do HtDP Exercise 150
Exercise 3 HtDP Exercise 165
Exercise 4 HtDP Exercise 155
Exercise 5 Design a function eliminate, that takes a List of Numbers lon and a Number n, and constructs a new List of Numbers with all the same values as lonexcept for any numbers equal to n. For instance,
(check-expect (eliminate (cons 5 (cons 4 (cons 5 (cons 2 ‘())))) 5) (cons 4 (cons 2 ‘()))) Note: this is essentially remove-all, simplified to lists of only numbers. We have not addressed how equal? works yet, so the full flexibility of remove-all doesn’t yet make sense. Also – do not use remove-all to implement this function!
Challenge (optional): Design a function no-dups, that takes a List of Numbers, and constructs a new list with any duplicate values removed (and keeping just a single one of the copies). For example,
Exercise 6 Complete the simple-net-forum assignment from Assignment 4b.
Assignment 5b
Due Date: Friday at 9:00pm (Week 5)
Purpose Further practice with lists.
Exercise 1 HtDP Exercise 142
Exercise 2 HtDP Exercise 143
Exercise 3 HtDP Exercise 145
Exercise 4 We know that cons allows us to add a number to the front of a list of numbers. Design its opposite, snoc, that allows us to add a number onto the end of a list of numbers.
Exercise 5 Design a function search-for-string that takes a string and a list of strings, and returns a list containing all the strings in the given list that contain the given string as a substring.
Hint: There are other string-processing functions besides substring; one of them is very useful for this problem. Look up the documentation for substring, and scroll up through the documentation to find a function that might help with checking string containment…
Assignment 6a
Due Date: Monday Tuesday at 9:00pm (Week 6)
Purpose Further practice with lists.
Exercise 1 HtDP Exercise 167
Exercise 2 HtDP Exercise 170
Exercise 3 Work through section 10.3, and do HtDP Exercise 172 (this is a long problem, but useful practice)
Exercise 4 Consider the following data definition:
(define-struct contact [name phone]) ; A Contact is a (make-contact String Number) ; An AddressBook is one of: ; – ‘() ; – (cons Contact AddressBook) ; INTERPRETATION: A list of contacts, with their names and addresses ; A MaybeNumber is one of ; – #false ; – Number ; INTERPRETATION: Represents maybe having a number Write the function find-contact that accepts a String representing the name of a contact and an AddressBook, and returns a MaybeNumber: either the first Number in the AddressBook for a Contact with that name, or if such a contact does not exist, find-contact should return #false.
Graded Exercises
Exercise 5 Consider the following data defintion:
; A Size is one of: ; – “small” ; – “medium” ; – “large” (define-struct drip-coffee [cream size]) (define-struct latte [size]) (define-struct cortado [size]) ; A Coffee is one of: ; – (make-drip-coffee Boolean Size) ; – (make-latte Size) ; – (make-cortado Size) ; INTERPRETATION: Represents three possible coffee orders. Each order ; has a size; drip coffee might also have cream in it. ; A CoffeeOrder is a List-of-Coffee ; INTERPRETATION: The list of coffee orders at a local coffee shop ; A MaybeCoffee is one of ; – #false ; – Coffee ; INTERPRETATION: Represents maybe having a Coffee Design the function last-latte that accepts a CoffeeOrder and returns a Coffeerepresenting the last latte order (i.e., a (make-latte …)) in the list. If there are no lattes in the CoffeeOrder, it returns #false.
Hint: follow the design recipe carefully here. Be careful with your signatures and templates, and they will help guide your implementation.
Exercise 6 Design examples for the next Forum assignment in Assignment 7a.NOTE: We are giving you a full week to implement this part of the project; it will be due next Monday instead of this Thursday.