Assignment 9

Due Date : 11/26 @ 11:59pm

Instructions

Each of you should have a repository in GitHub with the name assignment9-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 assignment9-githubHandle, where githubHandle is your GitHub account name, e.g,assignment9-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.

Problem 1

Write a function find-string that takes in a Listof[String] and a String and that returns a Boolean, true if and only if the given string was in the list.

Abstract find-string to generic-find-string so that the string comparison operation it uses is a parameter. Then use this abstraction to define find-string-case-sensitive, which should operate the same way as the original find-string, and find-string-case-insensitive, which has the same contract as find-string but which ignores the case of alphabetic characters when comparing strings (i.e. the character a is considered the same as A and so on; non-alphabetic characters must still match exactly).

Problem 2

DrRacket has lots of abstract functions for processing lists (pg. 313, Sect. 21.2, or the online version).

Given the following data definitions:

;; A Grade is: (make-grade Symbol Number)
(define-struct grade (letter num))

;; The Symbol in a Grade represents

;;    'A  >= 90
;;    'B  >= 80
;;    'C  >= 70
;;    'D  >= 60 
;;    'F  < 60

;; A Listof[Grades] ...
(define grades 
  (list (make-grade 'D 62) (make-grade 'C 79) (make-grade 'A 93) (make-grade 'B 84) 
        (make-grade 'F 57) (make-grade 'F 38) (make-grade 'A 90) (make-grade 'A 95)
        (make-grade 'C 76) (make-grade 'A 90) (make-grade 'F 55) (make-grade 'C 74)
        (make-grade 'A 92) (make-grade 'B 86) (make-grade 'F 43) (make-grade 'C 73)))
    

Design the requested functions to manipulate Grades. You must use the given list as one of your tests. For each you may use a local function.

Note: if you do not use the DrRacket loop function mentioned, you will not recieve credit for the sub-problem!

  1. Design the function log->lon that converts a Listof[Grade] into a Listof[Number] that contains just the numerical grade, using the Scheme function map.
  2. Using foldr, design the function best-grade that finds the highest Grade in a Listof[Grade].
  3. Design a function just-As that returns a list of only the 'A grades, using filter.
  4. Use andmap to design the function all-pass? that checks to see if all the Grades in a given list are not 'F.
  5. Finally design the function bonus that adds 5 to all of the Grades in a given list, and updates the letter portion of the Grade if it changes. Use map to design your function... it must return a Listof[Grade]!

Problem 3

You are provided with the following data definition

;; A [BT X] is one of 
;; - 'leaf
;; - (make-node X [BT X] [BT X])


(define-struct node (val left right))
;; interpretation: represents a node with a value
;; a left and right subtree
        

Without using any loop functions implement the following functions

  1. tree-sum, consumes a [BT Number] and returns the sum of all numbers in [BT Number]
  2. tree-prod, consumes a [BT Number] and returns the product of all numbers in [BT Number]
  3. tree-append, consumes a [BT String] and returns the concatenation of all strings in [BT String]

Abstract over the implementation of the preceding functions to create a function called tree-op-generic that will consume a [BT X] and any other arguments you think might be needed.

Use tree-op-generic to implement tree-sum.v2, tree-prod.v2 and tree-append.v2 that have the same behaviour as tree-sum, tree-prod and tree-append.

Problem 4

Use local and "loops" (abstractions such as map, filter, foldr, etc) to refactor your Missile Defense program.