©2005 Felleisen, Proulx, et. al.

Unions

1.6  Problem (4.3.2)

Consider this the following problem:

Develop a program that creates a gallery from three different kinds of media: images (gif), texts (txt), and sounds (mp3). All have names for source files and sizes (number of bytes). Images also include information about the height, the width, and the quality of the image. Texts specify the number of lines needed for visual representation. Sounds include information about the playing time of the recording, given in seconds.

Develop a data representation for these media. Then represent these three examples with objects:

  1. an image, stored in flower.gif; size: 57,234 bytes; width: 100 pixels; height: 50 pixels; quality: medium;

  2. a text, stored in welcome.txt; size: 5,312 bytes; 830 lines;

  3. a music piece, stored in theme.mp3; size: 40960 bytes, playing time 3 minutes and 20 seconds.