Assignment 2
Due Date Thursday 01/17 at 9pm
Purpose To write simple functions & tests relating to numbers, images, and strings
You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions. Failure to submit a .rkt file will result in a 0.
You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.
Your code MUST conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses so please remember to read it before submitting each assignment.
It would be good practice to make use of the design recipe when completing this assignment but since you JUST learned it, we will not yet penalize you if you do not include it.
You are required to provide sufficient testing for all functions.
Graded Exercises
Exercise 1 Write a function, starts-with? which, given two Strings, produces #true if the first string starts with the second. That is, (starts-with "hello" "h") should produce #true but (starts-with "h" "hello") should produce #false. Remember to provide sufficient tests for this function.
Exercise 2 Recall that in homework 1 we asked you to write the function pig-latinize. This function was a poor imitation of Pig Latin since it only worked if the given word began with a consonant. Re-write the function so that if given a word that starts with a vowel ("a", "e", "i", "o", or "u") it produces the word with the suffix "way" added (e.g. if given "oatmeal" we expect your function to produce "oatmealway"). Note that this still doesn’t quite capture the rules of pig latin (given "crater" your function will still produce "ratercay") but it is one step closer. Remember to provide sufficient tests for this function.
Hint: What function have you already written that might come in handy?
Exercise 3 The MBTA has realized that nobody likes getting back $1 coins as change when they buy a Charlie Ticket. Therefore they have decided to switch to giving back quarters! Much better. Write a function, convert-to-quarters which, given a number of $10 bills, a number of $5 bills, and a number of $1 bills, produces the total amount of quarters you need to give to someone to have the same amount of money as was input. Remember to provide sufficient tests for this function.
Exercise 4 In the BizzBuzz Game players count up to 50, replacing each multiple of 7 with the word "Buzz" and each multiple of 5 with the word "Bizz". Write a function, bizzbuzz which, given a Number outputs "Bizz" if the number is a multiple of 5, "Buzz" if the number is a multiple of 7, and "Bizzbuzz" if the number is a multiple of both 5 and 7. If a number is neither a multiple of 5 nor a multiple of 7, your function should just produce the number unchanged. Remember to provide sufficient tests for this function. WARNING: Be careful with your signature here if you decide to write one!
Exercise 5 Complete Exercise 28 in section 2.3 of the textbook. Please note that you will not be able to understand this exercise without first reading the section. You may write your answers in a comment.
Exercise 6 Complete Exercise 48 in section 4.2 of the textbook. Please note that you will not be able to understand this exercise without first reading the section. In a comment, explain each step of the evaluation process.
Exercise 7 Write a function, bigger-image which, given two Images, produces the image that has a larger area (height x width). If they are the same size you may produce either image.