6.6

Assignment 4

home work!

Programming Language BSL

Due Date Monday 9/24 at 9pm

Purpose To practice designing data definitions, start work on the course project, and practice using structures.

Expectations
  • You should submit a single .rkt file containing your response via the Handin Server. We accept NO email submissions.

  • You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.

  • All steps of the design recipe are required.

Project (Part 0)

Exercise 1 Over the next few weeks, we will be building up a world program that is a music player. Eventually, it will be fancy and will support many features. But for now, we’ll start small.

This week, you are going to design only the data definition that will serve as the basis for the first iteration. You are to design the data definition(s) needed for a simple song-playing program that has two features: (1) it is able to play exactly two songs repeatedly, and (2) it displays the user feedback from the most recent song played. The songs themselves are represented by Strings, which contain the actual bytes of data in the song file. Thus, the program needs to keep track of the content of the current song, the content of the next song, and the feedback supplied after playing the current song.

The user feedback will eventually be supplied via a set of three options presented to the user: a Like button that returns to you the feedback "like", a Dislike button that returns to you the feedback "dislike", or the user dismissing the window (which returns to you the feedback "none"). If no song has yet been played, the program should not display any feedback.

When designing the data definition, remember to follow all the steps for designing a data definition. When defining data examples, it is fine to use the empty string as the representation of a song, since encoding sound files is well outside the scope of this course.

Manhattan Distance

Exercise 2 Design the function manhattan-distance, which computes the distance between two points on a grid moving strictly on a horizontal and/or vertical path (that is, along the grid lines). The points are taken in as Posns.

Planets

(define-struct planet [name radius rings])
; A Planet is a (make-planet String Number Int)
; and represents a planet's name, radius (in km), and # of rings
 
(define EARTH (make-planet "Earth" 6371 0))
(define SATURN (make-planet "Saturn" 58232 7))

Exercise 3 What functions are given by (define-struct planet [name radius rings])? List them in comments, and provide their signatures (in regards to Planets).

Exercise 4 Design the template for Planets.

Exercise 5 Design the function ring-discovered, which given a Planet outputs the same planet but with 1 added to its ring count.

Exercise 6 Design the function bigger-planet, which given two Planets outputs the name of the one with the bigger radius. In event of a tie, output "Tied: <n1> - <n2>", where "<n1>" and "<n2>" are the names of the two planets given.