Assignment 5

Due Date : 10/16 @ 11:59pm

Instructions

Each of you should have a repository in GitHub with the name assignment5-githubHandle. Use this repository and add all your work there. In order to clone the repositories from GitHub to your machine (or watch this video video instructions):

  1. Sign in to GitHub.

  2. On your GitHub home page your Github Handle should appear on the left as a button/drop down menu. Click that button and from the drop down menu select cs2500f14. The GitHub page will then navigate to the class' web page and to the contents that is available to you.

  3. On the right you should be able to see all repositories to which you have been given access. Find the repository whose name matches the pattern assignment5-githubHandle, where githubHandle is your GitHub account name, e.g,assignment5-john123, and click on it.

  4. On the repositories home page look at the bottom right hand corner for a button with the text Clone in Desktop. By clicking on this button your browser will launch the GitHub client that we installed in class and ask for a location on your drive to store the repository.

    If you are not using the GitHub client the clone URL is located above the Clone in Desktop button. Copy the URL and issue the following command on your shell git clone URL.

  5. Create a file and save it under the folder on your drive that you selected in the preceding step.

Remember to push your changes to the GitHub repository often.

Note

For each question that asks you to design a program you are expected to follow the Design Recipe in the same way as we did in class. Failure to show all your work for each step will cost you points. All tests should use check-expect.

For this assignment you are not allowed to use any of the functions that operate on lists provided by DrRacket libraries.

Problem 1

Develop the following functions

  1. onlyTrue consumes a list of booleans and returns a new list with all false values removed
  2. replaceAll consumes a list of symbols and a symbol s and removes all occurrences of s in the list.
  3. replaceOnce consumes a list of symbols and a symbol s and removes the first occurrence of s in the list.

Remember to follow the design recipe.

Problem 2

Design a program that consumes a list of Posn, the maximum width and maximum height of a scene and returns back the list of Posns that are within the bounds of the scene.

Problem 3

You are given the following data definition

;; A Student is (make-student String Number Number Number)
;; interpretation: represents a student with their login, midterm grade, 
;; final grade and project grade.    
(define-struct student (login midterm final project))

  1. Provide a data definition for List of Students
  2. Design a program that consumes a list of Students and returns a list of their project grade
  3. Design a program that consumes a list of Students and returns a list of their average (average = (midterm grade + final grade + project grade) / 3)

Problem 4

Design the function snoc that consumes a list of numbers lst and a number n and returns the lst with n appended at the end of the list, e.g. (snoc (cons 1 (cons 2 empty)) 3) returns (cons 1 (cons 2 (cons 3 empty))).

Note: You are not allowed to use any library functions like reverse or append

Problem 5

Suppose we have the following class of data:
            (define-struct ball (x y color))
            ;; Ball = (make-ball Number Number Color)
            ;; Color is one of 'red, 'yellow, 'blue, etc.
    
Think of instances of ball as a Cartesian point, specifying where the ball is located, and the color of the ball.

Provide a data definition for lists of Balls.

Provide a template for processing such lists.

Design the function lob-length, which counts how many Balls are on a given list of Balls.

Design the function lob-draw, which consumes a list of Balls and adds them to an empty scene of 300 x 300 as appropriately colored circles of radius 3.

Design lob-member?. The function consumes a list of Balls, lob, and a Ball b and determines whether b occurs in lob.