Please note: This assignment is to be completed with your assigned partner
Purpose
The goal of this problem set is for you to gain practice 1) expressing mathematical relationships between values as BSL functions, 2) using conditional expressions, enumerations, and intervals, and 3) communicating your designs to others.
Design & Code Style
Design and code style are both essential to effective programming, and thus each will be graded. For design, we expect you to follow the six-step Design Recipe presented in HtDP/2e, §3.1. For style, it means that:
- No line may exceed 80 columns in length. How? Go to Racket Preferences > Editing > General Editing, and enable the “maximum character width guard.”
- The program must be properly indented, including the comments. How? Select some code and press Tab to automatically reindent just that code, or press Cmd/Ctl + I to reindent the whole file.
- Function and constant names must be descriptive, and argument names often should be.
- The program must follow the same naming conventions
as the textbook.
What?
For example, function names are
all-lowercase
, datatype names areInitial-uppercase
orUpperCamelCase
, and constant names areALL-UPPERCASE
. In each case, words are separated by hyphens (-
).
Problems
-
Consider the formulas that you derived for problems 1, 2, and 3 of Homework 0. Formulate each of these as a BSL function. (Be sure to follow the Design Recipe. This means that each function has a signature, a purpose statement, descriptive name, at least 2 examples, and complete test coverage.)
-
Write a data definition for the filling choices given in problem 4 of Homework 0, and write another data definition for the choice of sauces.
Bonus: Can you design a data definition to represent all possible ravioli orders with one choice of filling and one choice of sauce? For example, you should be able to represent the information butternut squash ravioli with cream sauce.. A
String
is not a suitable representation. -
Consider this data definition:
; An Orientation is one of: ; - "portait" ; - "landscape" ; - "square"
We consider the orientation of an image to be
"portrait"
if its height exceeds its width,"landscape"
if its width exceeds its height, or"square"
if its height and width are equal. Design a functionclassify-image
that, given anImage
, returns itsOrientation
. -
Design a function
string-prefix
that takes a numbern
and a strings
and produces a string containing the firstn
characters ofs
. (Hint: Use function composition.) -
At the end of EECS 111, your instructor will compute a numeric grade in the range 0 to 100, inclusive, for each student, and then convert that number to a letter grade. Suppose that the letter grade comes from this data definition:
; A Letter-grade is one of: ; - "A" ; - "B" ; - "C" ; - "D" ; - "F"
Suppose, further, that your instructor will give an A for numeric grades of 93 and above, B for grades from 85 up to but not including 93, C for [65, 85), D for [50, 65), and F for less than 50.
Formulate a more precise data definition than
Number
to specify the possibilities for numeric grades. Use intervals as in the definition ofWorldState
for the UFO exercise.Design a function to convert numeric grades to letter grades.
-
HTDP/2e, Exercise 47; except that:
- the maximum happiness level is fixed at 100 instead of being
passed as an argument to
gauge-prog
, and gauge-prog : World -> World
takes the initial happiness level as its parameter and passes that on tobig-bang
.
- the maximum happiness level is fixed at 100 instead of being
passed as an argument to
Evaluation
Your code will be evaluated for:
- design (how carefully your programming process has followed the Design Recipe),
- correctness (how closely your code’s behavior matches its specification, which is this web page),
- test coverage (whether every expression in every
function—except for gauge-prog—is
checked by some automated test, as with
orcheck-expect
check-within
), and - style (how readable it is, as measured by the rules listed above).
Turn In
Please write all your code in one .rkt
file and
submit it through
Canvas.