8.15

Homework 1🔗

home work!

Programming Language BSL

Due Date: Wednesday January 15, 9pm

Purpose Logistics; To write simple functions & tests relating to numbers, images, and strings

Expectations

Graded Exercises

These exercises should all be completed in a single .rkt file which you should submit via the Handin Server. Please note that you can submit as many times as you like but only your most recent submission will be graded. This means that if you submit twice, once before the deadline and once after the deadline, the submission made after the deadline will be graded, and penalized accordingly.

We will cover writing formal tests in an upcoming class. For now, when we ask you to write tests of your functions, do so in the following format. Let’s take the function sqr as an example: just above the function definition, add something like:

; (sqr 2) should be 4
; (sqr 10) should be 100
; (sqr 1) should be 1

Exercise 1 Search the course website to find the style guide. In a comment, write the course policy on hanging parentheses. We expect you to follow this policy and will grade your assignments accordingly.

Exercise 2 In a comment, write the four forms of atomic data introduced in Chapter 1 of the textbook.

Exercise 3 In Pig Latin words that begin with a consonant are shifted so that the first letter goes to the end of the word and is then followed by the suffix "ay". Write a function, pig-latinize that, given a word, follows this pattern. You may assume that the word begins with a consonant and that moving the first letter is enough (that is, given the word "crater" we expect the function to produce "ratercay" even though this is not quite how Pig Latin works). Write at least 2 tests for this function.

Hint: The String function documentation is a useful place to look for functions that operate on Strings.

Exercise 4 Write a function, middle, which, given three arguments, produces the second one. Provide at least two tests for this function. In a comment, explain what types of values this function can take as inputs and what types of values it can produce.

Exercise 5 Yak Travel Agency arranges trips for climbing Mount Everest. For each trip, they charge an initial fee in addition to $0.15 for each vertical meter climbed. For instance, the price for climbing all the way to the summit, which is 3500 meters above the base of the mountain, is $645. Define a BSL function which, given the number of vertical meters climbed, produces the cost of a trip led by the Yak Travel Agency. Write at least two tests for this function.

Hint: it can be useful to write out a table of input/output pairs to help understand these types of mathematical relationships (and these can then provide great tests!)

Exercises 6 and 7 will ask you to provide "sufficient" tests. We are looking for you to test all the interesting cases of the function. This includes each case of any conditionals you write, as well as edge cases (when the inputs are on the edge of a condition).

Exercise 6 Write a function, valid-date? which, given a String representing the month of the year (e.g. "January") and a Number representing the day of the month, returns a Boolean if this is a valid date. Your function should return true if the date is sometimes valid (e.g. February 29th). You should also provide sufficient tests for this function.

Exercise 7 Complete exercise 17 in section 2.1 of the textbook. You should also provide sufficient tests for this function.

Hint: The Image function documentation is a useful place to look for functions that operate on Images.

Exercise 8 In this exercise you will build a scene by defining a constant with a sensible name for each of the parts. The final scene should look similar to this:

house scene

You aren’t required to reproduce this exactly, but it should be close and adhere to the descriptions below. You may use the DrRacket documentation to find helpful functions. Note: extra credit will be given if the constants build on each other well and if the final scene resizes based on the side length of the square background.

  • A small, yellow circle in the upper-left corner region of a rectangle whose top 80% is light-blue and bottom 20% is dark brown

  • A forestgreen, thin oval overlapping the top of a tall light brown rectangle

  • A gold square with a red triangle on top, a tall purple rectangle in its bottom middle, and two orange-outlined squares equally spaced from the center and above the purple rectangle

  • On top of part (a), place part (b) on the left (level with the dark-brown portion of the image), and part (c) on the right (also level with the dark-brown portion of the image).