CS35 Lab 02: iSwat Media Library

Due 11:59pm Sunday, February 5 2017

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

For this assignment, you will be working with a partner. In future assignments, you will be able to select your partner. However, for this lab, we have assigned partners for you. 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 your partner.

You and your lab partner will share the same git repository, which is named lab02-<user1>-<user2>.git Please access your lab by cloning the appropriate git repository, e.g.:

$ git clone git@github.swarthmore.edu:CS35-s17/lab01-jbrody1-adanner1.git
We've given you a skeleton version of the program.

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

In addition, you will create a MediaLibrary class which acts as a container for up to 50 Media objects (think of how iTunes stores all of your eBooks, music, movies, etc.). You will also build capability in the MediaLibrary class for obtaining information about your different media objects and for playing the media itself.

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

The Media Class

The Media class contains virtual methods which are common to all media objects. See the method comments on the declarations fo those classes for more information about the behavior you need to implement.

The MediaLibrary Class

This class keeps track of all Media objects in a library. It allows a user to ask how many Media objects are in the library and gives them access to them on request. Its constructor takes in a single string which represents the name of the file containing the media library. In the MediaLibrary constructor, you should open this file and create Media objects accordingly.

The Media Library File

When the program starts, you should ask the user for the name of a media library file.
    $ ./iswamedia
    Welcome to the iSwat Media Library!
    What is the name of your media file? example1.library

    1. [image] Brown-Flames
    2. [image] Aliens
    3. [text] Gettysburg-Address
    0. (quit)

    What would you like to open?
The first line of the media library file should indicate the number of media objects it contains. Each item is represented by several lines depending on what kind of media it is: You can assume that each line of the media library file contains a single element with no whitespace.

For example, the following is a valid media library file.

The Application

As mentioned above, your main function should ask the user for the name of a media library file. Using that file, it should display a menu listing the media files (in order) and allow the user to pick a media file to open. Media files should be listed by positive integers (that is, the first media file you show should be selected by the input 1). After opening that media file, the menu should be repeated again; the program should continue in this fashion until zero is entered, after which it should terminate.

To display the media in a menu, you need to have a way of representing it. The getDescription method is virtual and unimplemented; each Media subclass implements it in a different way.

The act of opening a media file is also performed by the particular Media subclass. The open method of each Media object should behave as follows:

The system Function

The library cstdlib contains a function system which can run commands for you. You pass a C-style string to the system function and it will run it in much the same way as the shell we use to e.g. compile our programs. For instance, the following program will open Firefox to the Google home page. After it does that, it will open a text editor.

  #include <cstdlib>
  #include <string>

  using namespace std;

  int main(int argc, char** argv) {
    string cmd1 = "firefox http://www.google.com";
    string cmd2 = "gedit";


    return 0;

In larger applications, we avoid using the system function in favor of more precise ways to launch other programs from within our own code. For this lab, however, the system function suits us quite well.

Getting Started
We recommend implementing your program in 5 parts:
  1. Initial file I/O -- be able to read in an example media library from a file. For now, don't worry about actually using this information; just print the contents of the file to the screen so you know your file I/O is working.
  2. Text class -- be able to view a text file.
  3. Image and Video classes -- be able to open an image or play a video.
  4. Media Library -- build and test a MediaLibrary class which holds up to 50 media objects and lets the user access the objects.
  5. Finish the main program -- once you have your media objects and MediaLibrary set up, complete the program. When completed, your program should ask the user for a media library, present a menu of media objects, and allow the user to select and open the media.
Your program should use good design, and you should use defensive programming as you develop your code. Your program will be tested on your understanding on how to define C++ classes and use inheritance. In addition, you should implement small test functions in between each phase. Do not use your MediaLibrary to test and debug your Media objects.

Compiling Your Program

Your code in this assignment is broken in to several different files. To aid in the compilation process, we've created a Makefile which should make compilation easy. To compile your test program, just type:

      $ make manualTests
Compiling your main program is even easier. Just enter:
      $ make
Extra Challenges
There are many ways of extending this lab. If you're looking for an extra challenge, consider implementing one of the following: These additional features are optional -- we'll look at them, but they won't be for credit. Make sure you complete and push the main lab before starting any extra challenge, and note in your README file that you've done extra challenges so the graders know which version of your lab to grade. (There's a chance your added features will break our grading scripts; we'll grade the base version of your lab to ensure you don't get penalized in the off-chance your extra features break our grading scripts)
When you have completed your lab, answer a few short survey questions in the file README.md


To summarize the requirements of this lab:


Once you are satisfied with your code, hand it in using git. Remember the add, commit, push development cycle. You can push as many times as you like, but only the most recent submission will be graded. You may want to run git status to confirm all modifications have been pushed.