| Problem Set 6h | ||||||||||||||||||||||||||
Due date: 10/24 @ 11:59pm
Honors-section homework
Exam GradesYour professors and TAs have been grading Exam 1. We were each assigned a pile of exams to grade and when we're done grading we turn in a list of exam grades for each of the students in our pile. Here is the data definition for exam grades and lists of exam grades: (define-struct examgrade (student points comment)) ;; An ExamGrade is a (make-examgrade String Number String) ;; A LOEG (list of exam grades) is one of: ;; - empty ;; - (cons ExamGrade LOEG) Each exam grade records the name of the student, the student's points on the exam, and a comment from the grader. Exercise 1:
Design a function, Exercise 2: Professor Ahmed has just been given two lists
of exam grades for the students in the honors section. The first list
contains students' grades for the regular exam, while the second
contains grades for the honors supplement. She wants you to design a
function, Here are some examples (but you should develop more of your own): (honors-totals (list (make-examgrade "Amal Ahmed" 58 "Aced it!") (make-examgrade "Olin Shivers" 30 "Not so good")) (list (make-examgrade "Amal Ahmed" 44 "Wow!") (make-examgrade "Olin Shivers" 25 ""))) ---> (list (make-examgrade "Amal Ahmed" 102 "") (make-examgrade "Olin Shivers" 55 "")) (honors-totals (list (make-examgrade "Amal Ahmed" 58 "Aced it!") (make-examgrade "Olin Shivers" 30 "Not so good")) (list (make-examgrade "Leena Razzaq" 38 "") (make-examgrade "Olin Shivers" 25 ""))) ---> (list (make-examgrade "Amal Ahmed" 58 "Missing honors") (make-examgrade "Leena Razzaq" 38 "Missing regular") (make-examgrade "Olin Shivers" 55 "")) Legos!Here are data definitions for lego bricks and lego buildings: (define-struct lego (label color width)) ;; A Lego is a (make-lego Number Symbol Number) (define-struct bigger (lego left right)) ;; A LegoBldg (lego building) is one of: ;; - Lego ;; - (make-bigger Lego LegoBldg LegoBldg) Each lego brick has a label, color, and width (in pixels). We construct a lego building out of lego bricks, and make bigger buildings by putting a lego brick on top of two lego buildings (left and right). Exercise 3:
Design a function, Exercise 4:
Each lego brick is 10 pixels tall.
Design a function, Exercise 5:
Design a function, Exercise 6:
Design a function, Here is a data definition for the type of data this function returns: ;; A MaybeLego is one of: ;; - false ;; - Lego
Your function should not use Exercise 7:
Design a function, Design a function, Here are some examples: (make-bigger (make-lego 4 'purple 80) (make-bigger (make-lego 2 'blue 60) (make-lego 1 'yellow 40) (make-lego 3 'red 40)) (make-bigger (make-lego 6 'orange 60) (make-lego 5 'green 40) (make-lego 7 'red 40))) (make-bigger (make-lego 4 'purple 80) (make-bigger (make-lego 2 'blue 60) (make-lego 1 'yellow 40) (make-lego 3 'red 40)) (make-lego 6 'orange 60)) Exercise 8:
Design a function,
Here's how two legos
Here are some examples to illustrate: (merge-lb (make-bigger (make-lego 2 'blue 60) (make-lego 1 'yellow 40) (make-lego 3 'red 40)) (make-bigger (make-lego 2 'blue 60) (make-lego 1 'yellow 40) (make-lego 11 'red 20))) ---> (make-bigger (make-lego 2.2 'blue 120) (make-lego 1.1 'yellow 80) (make-lego 3.11 'red 60)) (merge-lb (make-bigger (make-lego 4 'purple 80) (make-bigger (make-lego 2 'blue 60) (make-lego 1 'yellow 40) (make-lego 3 'red 40)) (make-lego 6 'orange 60)) (make-bigger (make-lego 4 'purple 80) (make-lego 2 'blue 60) (make-bigger (make-lego 6 'orange 60) (make-lego 5 'green 40) (make-lego 7 'red 40)))) ---> (make-bigger (make-lego 4.4 'purple 160) (make-lego 2.2 'blue 120) (make-lego 6.6 'orange 120))) Orderly LegosLet's build a different kind of lego building where all legos in the building must have distinct labels and brick labels appear in a certain order in the building.Here is the data definition for our ordered lego buildings: ;; An OrdLegoBldg (ordered lego building) is one of: ;; - 'none ;; - Lego ;; - (make-bigger Lego LegoBldg LegoBldg) ;; where each lego brick in the building has a unique label and ;; where each (make-bigger l lft rgt) has the property that ;; -- the label of l is bigger than all the labels in lft ;; -- the label of l is smaller than all the labels in rgt
All functions that you design below must exploit/maintain the
distinct-label and label-ordering properties of
Exercise 9:
Design a function, Exercise 10:
Design a function,
You may use Exercise 11:
Design a function, Exercise 12:
Design a function, X-ExpressionsHere is the data definition for X-expressions:
X-expressions are used to represent XML information within the BSL language
The "teachpack" more-io.ss provides the
function read-xexpr for reading an entire XML files as an
X-expression. To use the teachpack, save it in the same directory as
your code for the problem set. In DrRacket, select the Language >
"Add Teachpack..." menu item, then "Add Teachpack to
List...", then navigate to the location of
Before submitting, any use of Here is a sample XML piece: <week> <assignment> hello <syllabus week="2" src="sample2.xml" /> <syllabus week="1" src="sample1.xml"> world </syllabus> </assignment> done </week> Exercise 13: Represent it as an X-expression to practice your data representation skills. Exercise 14: Your task is to design four functions:
You should notice that two of the functions are one-line definitions, if you use function composition to define them. For your entertainment, this assignment comes with the XML file 6h.xml, which stores information about this assignment. You may use it to run your program (not test). For testing, you must create a simpler file than this.
Exercise 15: The last problem required the design of the
functions: The first step to editing such clusters of functions after they have been properly designed and corrected is to re-organize them into a single function, just like the problem statement (or your boss's request) states for both of the two functions in this problem. Do so.
The reason for organizing code in this manner is to create an
organizational structure for future
readers. If
Exercise 16: XML experts refer to (the interpretation of) an Xexpr as an
element. Design the function
Exercise 17: Abstract
over Hint: Start from the template for all three functions. (Remember that since all three functions process the same kind of input data their templates---i.e., their organizational skeletons---are identical. Then create a function that consumes appropriate "combinators" and "base values" for the various clauses that must be distinct. Knowledge: This abstraction is at the core of many XML processing languages and thus shows up at the heart of many XML libraries. |
last updated on Sun Dec 2 14:52:34 EST 2012 | generated with Racket |