Assignment 3
Due Date Thursday 01/24 at 9pm
Purpose To design small programs and practice using enumerated data.
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.
You must provide sufficient tests for all your functions.
Please be sure to look at the feedback for assignment 1 before submitting, as we will be grading you more harshly on things we have warned you about before.
Graded Exercises
These first few exercises will walk you through the design of a simple world program using enumerated data. Note that these exercises are "bottom up": that is, we design some smaller functions first and then make use of them later in the larger program. Ordinarily we ask you to design your programs "top down" instead but this way allows us to explain each step more clearly. For more information on top down programming see the style guide on the course website.
; A DayOfWeek is one of: ; - "Monday" ; - "Tuesday" ; - "Wednesday" ; - "Thursday" ; - "Friday" ; - "Saturday" ; - "Sunday" ; and represents a day of the week
Exercise 1 Define three distinct examples of DayOfWeeks.
Exercise 2 Design the template for a function that takes in a DayOfWeek.
Check out the docs on on-key for the definition of a KeyEvent.
Exercise 3 Design a function which, given a DayOfWeek produces the next day of the week. For example when given "Sunday" your function should produce "Monday".
Exercise 4 Design a function which is given a DayOfWeek and a KeyEvent. If the key event is "right" the function outputs the next day in the sequence (Monday->Tuesday->Wednesday...). Otherwise it simply outputs the given day.
Exercise 5 Design a function which, given a DayOfWeek, draws it on an empty-scene. Use constants for your font size and color as well as your background scene.
Exercise 6 Design a function calendar which takes in a DayOfWeek (the first day you want to display) and launches a big-bang program that lets someone cycle through the days of the week by pressing the right arrow key.
The following exercise asks you to design an entire world program from scratch. Please refer to the textbook for more information on what this entails and remember that we expect your program to be designed "top down". And, as always, please come to office hours if you have any questions.
Exercise 7 Design a program which emulates a car’s crash test. Initially, the car should start on the left edge of the screen, then as time goes on it should drive towards the right edge at a steady pace. When it reaches the right edge you should display an explosion of some kind to indicate it has crashed. It may be helpful to review Chapter 3 of the textbook and in particular section 3.6 which focuses on the design of world programs.
Exercise 8 Write the following expressions in their simplest form: