CS35 Lab 2: iSwat Media Library

Due 11:59pm Sunday, September 22, 2013

The goal of this lab is to introduce you to basic concepts in the C++ program language. Concepts you will be familiar with after this lab include:

In addition, you will become somewhat familiar with making system calls from within your C++ program.

A skeleton version the program will appear in your cs35/labs/02 directory when you run update35. The program handin35 will only submit files in this directory. You may choose one partner for this lab. Both partners should be present and working on the code together. You will both be responsible for understanding all concepts, so dividing and conquering is not an option. The academic integrity policy applies to the entire pair; you cannot work or share code with anyone outside of your partner. Also, be sure to indicate who your partner is by including both names in the header and by also selecting the 'p' option when using handin35. Only one student in the pair should submit the lab.

Introduction

In this lab, you will create several classes representing different types of media, including pictures, books, and video. All of these classes will be subclasses of an abstract Media class. This Media class will encapsulate all information and functionality that is common to all types of media. Your subclasses will add additional unique data and methods as well as implement inherited methods to be specific. For instance, "opening" a book should be different than "opening" a picture or video.

In addition, you will create a MediaLibrary class, which acts as a container for several Media objects (think of how iTunes stores all of your eBooks, music, video, etc.). You will also build capability in the MediaLibrary class for obtaining information about your different media objects and for playing the media itself. This will be different than most projects you have completed in that the main user interface will be handled by an object. Below is an overview of the files required for submitting this week's lab. Those highlighted in blue will require implementation on your part. Those in black are complete and should not be modified except for comments.


Program Requirements

I recommend implementing your program in 3 phases:

  1. Media and Picture classes -- be able to view a picture.
  2. Book and Video classes -- be able to open a book or play a video.
  3. Media Library -- build and test a MediaLibrary class that holds several media objects and lets the user get information and/or open each object.
Your program should use proper design, and you should use defensive programming as you develop your code. Your program will be tested on your use of modular functions and understanding of how to define C++ classes and use inheritance. In addition, you should implement small test programs in between each phase. Do not use your MediaLibrary to test and debug your Media objects. You will assuredly go insane tracking down errors if you wait that long to test.


I. Media and Picture classes

Your program will need to handle several types of media. To get started, first review the Media and Picture classes.

The Media class has been implemented for you. But you must start but understanding this class. The Media class encapsulates all information and methods common to all media types. In particular, it contains:

We have provided skeleton code for both media.h and media.cpp. Note that since there is no definition for how to open() a Media object, you cannot actually create an instance of the Media class. This is what is known as an abstract class - it forms the template for subclasses you want to define later. In this way, it is a contract: anything that inherits the Media class must complete a unique open method. And any user who wants to create Media objects must chose a specific subclass (e.g., Picture, Book, Video).

The Picture class should specialize (i.e., inherit) Media and implement any information particular to pictures. In particular: Before moving onto the second phase of this lab, modify testMedia.cpp to test your class. This program should create a Picture object and then open the picture. This picture can be one of the images from Lab 01, or one of your own images. You should test, at a minimum, all methods whether inherited or not, before moving forward.

To compile incrementally, first compile the Picture class by itself to make sure you have no errors:

$ g++ -c picture.cpp
We have provided a Makefile that automates the process. To compile one of the classes, simple follow this example:
$ make picture.o
This executes the command given above. When you are ready to use testMedia, run:
$ make testMedia

II. Book and Video classes

Once you have successfully created and opened a Picture object, you can begin creating other media objects. Note that there are no files provided for you, you need to create them from scratch.

The Video class should specialize Media, just like the Picture class. You should define your header and implementation file in video.h and video.cpp, respectively. In addition to what it inherits from Media, your Video class should comply with the following:

An example creation of a Video object will be similar to the following:
Video testVideo("Hello Heisman","http://www.youtube.com/watch?v=YxpoqP9PkqM", 123);
After creating the video class, write a a new function in testMedia.cpp. This function should create a Video object and play the video to thoroughly test its capabilities. NOTE: the Makefile currently does not have the capability to compile the Video class. You will need to edit lines 4 and 6. This is as simple as moving the comment mark after the terms video.o and video.h.

Next, create a Book class in book.h and book.cpp. We have given a starting point for these files. This should also specialize the Media class. This class will be the most intricate of the three as you will turn your computer into an eBook reader when loading the book. In addition to the inherited methods/data, your class should:


III. The Media Library

Finally, you should build a MediaLibrary class. This class should store a collection of Media objects and allow a user to list, get details, and open the media contained in the MediaLibrary.
We have provided initial header and implementation file (i.e., mediaPlayer.h, mediaPlayer.cpp). We have also implemented the run method, which gives the user a list of commands and calls the corresponding class methods. Here is what you need to do:


Check List and Sample Output

To recap, you are required to to the following:

There are two sources of expected output you can use to help ensure your program is working. The first is a sample run using testLibrary.txt. For obvious reasons, the test does not show an example of opening a picture or video, but does do simple operations with a book. In addition, I have provided an executable for a working version of the program that you can test dynamically. Simply run the following command:

$ ~soni/public/cs35/mediaLibrary/main


Submit

Once you are satisfied with your code, hand it in by typing handin35. This will copy the code from your cs35/labs/02 to my grading directory. You may run handin35 as many times as you like, and only the most recent submission will be recorded. Please record your partner one time using the 'p' option.