In this module we introduce and apply the Design Recipe to a series of example problems. The examples introduce new kinds of data definitions, scalars and itemizations, and demonstrate how to use rackunit to develop tests for BSL functions.

  1. Use rackunit to write tests.
  2. Use rackunit to debug a function.
  3. List the four goals of testing.
  4. Explain the four goals of testing.
  5. Use the syntactical conventions for function definitions.
  6. Write a code example of scalar data.
  7. Define the term itemization.
  8. Use a bulleted list for an itemization data definition.
  9. Write the interpretation for simple data.
  10. List the six steps of the design recipe in order.
  11. Explain what each step of the Design Recipe does.
  12. Given a solution, label each step of the design recipe.
  13. Given a signature, write down its inputs.
  14. Given a signature, write down its outputs.
  15. Append predicate function names with the question mark character.
  16. Use the arrow to separate input and output in function signatures.

  • DUE DATE: January 28, 2016 @ 12:00pm
  • Instructions

    All problems must be solved using the Design Recipe and you must show all your work for every step in the Design Recipe. You code must also follow the class' coding style.

    Problem 1

    You are asked to provide a function in DrRacket that can convert dollar amounts to the equivalent euro amounts. You program can use the exchange rate of $1 = 0.89 Euro.

    Problem 2

    A classmate came up with the following Data Definition for a Cartesian Point

    
    ;; A CartesianPoint is (make-ca-point (Integer Integer))
    ;; INTERP: represents a cartesian point with its x and y coordinates
    (define-struct ca-point (x-coord y-coord)) 
                

    You are asked to provide a function in DrRacket that calculates the distance between two Cartesian points using the ca-point structure for Cartesian Points.

    Problem 3

    Design a program that given a number grade for a student returns back the letter grade as a string. Here is the table with the mapping from number grades to letter grades.

    Number Grade (g) Letter Grade
    95 < g <= 100 A+
    90 < g <= 95 A-
    85 < g <= 90 B+
    80 < g <= 85 B-
    75 < g <= 80 C+
    70 < g <= 75 C-
    60 < g <= 70 D
    g <= 60 E

    Problem 4

    For each of the following structure definitions provide

    1. Signatures for all selectors
    2. Signature for the constructor
    3. Signature for the predicate
    4. A template
    
    (define-struct student (name id grade))
    ;; A Student is (make-student String PosInt PosInt)
    ;; INTER: represents a student with the student's name 
    ;;        the student's id and the student's grade. 
    
    (define-struct container (width height depth capacity label))
    ;; A Container is (make-container PosInt PosInt PosInt PosInt Symbol)
    ;; INTERP: represents a container with its width, height, depth 
    ;;         in centimeters, it's capacity in cubic centimeters and 
    ;;         it's label
    
    
    (define-struct sweater (material size producer))
    ;; A Sweater is (make-sweater Symbol PosInt String)
    ;; INTERP: represents a sweater with the sweater's material 
    ;;         it's size and the name of the manufacturer
    
    (define-struct game (name min-ram min-graphics-ram online?))
    ;; A Game is (make-game String PosInt PosInt Boolean)
    ;; INTERP: represents a game with it's name, the minimum ram 
    ;;         capacity needed , the minimum graphics 
    ;;         card memory needed and whether it is an online game or not
    

    Problem 5

    You started working for a small company that produces cash registers. The company is currently designing their new model and one of your colleagues has provided you with the following data definitions

    
    
    ;; Dollars is a PosInt
    
    ;; Cents is a PosInt 
    ;; WHERE: Cents is greater or equal to 0 
    ;;        and less or equal to 99
    
    (define-struct amount (dollars cents))
    ;; An Amount is (make-amount Dollars Cents)
    ;; INTERP: represents total amount in dollars and cents. 
    

    You have been tasked to design the add-to-amount function that will consume the current amount, amt, the number of dollars, dollars, to add and the number of cents, cents, to add. Your function should return the amount after adding dollar and cents to amt.