Assignment 4
Due Date : 10/9 @ 11:59pm
Instructions
Each of you should have a repository in GitHub with the name
assignment4-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):
-
Sign in to GitHub.
-
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. -
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
assignment4-githubHandle
, where githubHandle is your GitHub account name, e.g,assignment4-john123
, and click on it. -
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
. - 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
.
Problem 1
A driving school in your area holds driving tests. In order for a registered student to get a driving license they need to complete both a written test and a driving test. For each registered student the school tracks the following information as one record
-
Identity card number, e.g.,
123456
-
zip code, e.g.
98001
- written test grade: number between 0 and 100
- driving test grade: number between 0 and 100
- Design a data definition and provide an interpretation for these records.
-
Design a function that given a student record returns
'pass
if- the students writen test score is more than 80, and
- the student driving test score is greater than or equal to 85
'failed
.
Problem 2
Provide templates for the following data definitions
(define-struct person (first last)) ;; A Person is (make-person String String) ;; interpretation: holds the first and second name for a person (define-struct affiliation (institution street-no street-name zip state country)) ;; An Affiliation is (make-affiliation String Number String Number Symbol String) ;; interpretation: holds the name of the instituion, institution's streen number and ;; street name, zip code state and country. State is given as a symbol of size 2, e.g. 'WA (define-struct date (year month day)) ;; A Date is (make-date Number Number Number) ;; interpretation: represents a date as YYYY MM DD (define-struct pub (title author affiliation date)) ;; A Pub is (make-pub Sring Person Affiliation Date) ;; interpretation: represents a publication with a title, ;; the name of the author, the author's affiliation and ;; the date of publication
Problem 3 (Exercise 95 from HTDP version 2)
The administration of your home town manages a fleet of vehicles: automobiles, vans, buses, SUVs, and trucks. Develop a data representation for vehicles. The representation of each vehicle must describe the number of passengers that it can comfortably accommodate, its license plate, and its fuel consumption (miles per gallon). Develop a template for functions that consume representations of vehicles.
Problem 4
Below is a data definition for a class of shapes (See the code at the bottom). Add an interpretation for the Square and Rectangle classes. Both represent shapes whose borders are parallel to the borders of a canvas (window).
Develop the template for functions that consume Shapes.
-
Use the template to design
shape-shift-x
. The function consumes a Shape,sh
, and a number,delta
. It produces a shape that is likesh
but shifted bydelta
pixels along the x-axis. -
Use the template to design
shape-in?
. The function consumes a Shape,sh
, and a Posn,p
, and determines whetherp
is inside (or on the boundary) ofsh
.
Domain Knowledge: for a point to be within a circle, its distance to the center must be smaller than (or equal to) the radius. For a point to be within a rectangle, its x coordinate must be between the x coordinate of the left line and the x coordinate of the right line. How do you compute the x coordinates of these lines? Naturally something analogous must hold for the y coordinates. Remember that squares are just special rectangles.
-
Use the template to design
shape-draw
. The function consumes a Shape,sh
and a Scene,sc
and addssh
tosc
.
;; --- copy and paste into DrRacket --- ;; Shape is one of: ;; -- Circle ;; -- Square ;; -- Rectangle (define-struct circl (x y r outline c)) ;; A Circle is a ;; (make-circl Number Number Number Boolean Symbol) ;; interpretation: x and y determine the center of the circle, ;; r the radius, outline whether it's outlined or solid, ;; and c its color (define-struct squar (x y size outline c)) ;; A Square is a ;; (make-squar Number Number Number Boolean Symbol) ;; interpretation: Supply a good interpretation of Square. (define-struct recta (x y width height outline c)) ;; A Rectangle is a ;; (make-recta Number Number Number Number Boolean Symbol) ;; interpretation: Supply a good interpretation of Rectangle. ;; ... problem solving steps ... ;; inspect for expected results: (define sh (make-squar 100 100 50 true 'red)) (define pt (make-posn 130 130)) (shape-in? sh pt) (shape-draw (make-circl 130 130 5 true 'red) (shape-draw sh (empty-scene 300 300)))