You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Homework 1

Due: 11:59pm, Tuesday, Sep 08, 2020

100 points

For all Racket assignments in this course, set the DrRacket Language to Advanced Student (under How to Design Programs). Your assignment will be graded using the specified language level. If you use a different language level, your code may not work when it is graded.

  • Carefully follow the Sample Solution to a Programming Problem in the Racket HW Guide. Less than half of the credit for each programming problem is based on the the correctness of your code as determined by our test cases. Most of the grade is based on how well you follow the design recipe.
  • Do the following programming problems:
    1. [10 pts] Develop the function contains?, which consumes a symbol and a list of symbols and determines whether or not the symbol occurs in the list.
    2. [10 ptsDevelop the function count-symbols, which consumes a list of symbols and produces the number of items in the list.
    3. [10 ptsDevelop the function count-numbers, which counts how many numbers are in a list of numbers. 
    4. [20 ptsDevelop the function 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. [Hint: develop several auxiliary functions (following the design recipe to develop each auxiliary function) that you can use to make the definition of average-price very easy.
    5. [10pts] Develop the function 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-exp (elim-exp 1.0 (cons 2.95 (cons .95 (cons 1.0 (cons 5 empty)))))
    6. [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
      
    7.  
  • Notes:
    • Be sure to do all the assigned parts of each problem. In the book, each problem ends with a block icon. Online, each problem ends with a hand icon.
    • In problem 9.5.7, the book asks you to write a function that checks for the empty list input as an error and throws an aborting error in the case. (The purpose statement should document this behavior!) In the newest version of DrScheme, the error function take a single argument not two arguments as documented in the book. We recommend using a string (text enclosed in double quotation marks like "This is sample string". You can test the error throwing behavior of a function using check-error which is documented in the DrScheme Help Desk.
    • Read chapter 8 very carefully before doing the problems from that chapter. This chapter is not padded with lots of wordy examples. In writing hand evaluations for problems 8.3.1 and 8.3.2, follow the same format as the evaluation examples given in the Scheme HW Guide.
    • To follow the design recipe, you must write down the purpose, contract, at least 5 well-chosen examples, write the code for the function, and include illustrative test cases for the function (using at least the examples you developed ahead of time). You can bundle the examples and test cases together as a block of check-expect invocations. Your chosen examples should illustrate the output you expect, and the test cases should produce the actual output (they should not be commented). If the function processes an inductive type, make sure that your examples include the base case(s) and sample inductive cases.

Submit your homework using the Comp 211 Owlspace page.

  • No labels