6.6

Homework 9

home work!

Programming Language ISL+

Due Date Friday, November 8 at 6pm

Purpose To practice working with multiple complex inputs.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions. Failure to submit a .rkt file will result in a 0.

  • You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.

  • Your code MUST conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses so please remember to read it before submitting each assignment.

  • You must follow all the steps of the design recipe when completing this assignment.

  • Please be sure to look at the feedback for assignment 7 before submitting, as we will be grading you more harshly on things we have warned you about before.

  • You must submit this assignment with your partner.

  • You must NOT use equal? in this assignment.

Exercise 1 Design the function read-lolon. The function is supplied the path to a file that contains space-separated numbers and it produces a list of lists of numbers, where each inner list is a row in the file. For example, given this file the following test should pass:
(check-expect (read-lolon "numbers.txt")
              (list
               (list 0 0 0 0)
               (list 1 2 3 4)
               (list 2 1 0 -0.5)))
The pre-defined function read-words/line will be very helpful to you here.

Exercise 2 It turns out that the map function can work for multiple input lists. For example, (map + (list 1 2) (list 3 4) (list 5 6)) would produce (list 9 12). To get a sense of how this works, you are to design the function map-2list, which takes a function and applies it to the first element of both lists, then the second of both lists, ... You are NOT allowed to use any list abstraction for this problem. The function should produce an error (using the error function) if the lists are not the same size (you can use check-error to check that your function works correctly in these cases).

Exercise 3 Design the function list=? that accepts two lists and an equivalence relation (a function that compares two elements of the same type to determine if they are equal) and determines whether the two lists have the same contents. For example (list=? (list "a" "bc") (list "d" "ef") (λ (a b) (= (string-length a) (string-length b)))) should produce true. You must implement two versions of this function: one that uses a list abstraction (hint: think about the revalation in the previous problem) and the other without.

Exercise 4 Design the function interleave that takes two lists and produces a list of their items, alternating from each list. If the lists have different lengths, just finish with all the remaining items of the longer list.

Exercise 5 You are to design a program that allows the user to take a true/false test. To take the test, the user calls the function take-tftest and supplies a path to the file containing the answer-question pairs; this function should return the proportion, (a number in the range [0, 1]), of questions answered correctly.

Each line of the file will start with the answer (either T or F), followed by a comma, and then the prompt of the question. A sample file is available here, but your program should be able to handle any file that matches this specification.

The program should start by showing the first question prompt. The user can then press the enter/return key to indicate they think the answer is true, or the escape key if they think the answer is false. Once one of these buttons is pressed, the program should display the original prompt, as well as the correct answer. The color of the correct answer should be green if the user answered correctly or red if they did not. The program must then wait for the user to press the space bar to continue to the next question, or, if there are none, end with a summary screen. The summary should include how many questions were answered correctly and how many questions were answered in total.