CS35 Lab 4: Light-Sabre Linked Lists

Due by 11:59pm Sunday, October 6, 2013
In this lab, you will implement a C++ linked list and then use that linked list to store a movie. Specifically, each node will represent one frame of the film as a string. You will then create a movie player program that will load a movie into a linked list and perform some basic operations for playing and editing the film.

To get started, run update35 from a computer science lab computer. The program update35 will create a cs35/labs/04 directory in your CS home directory, and the program handin35 will subsequently submit files from that 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 at the top of your files and by also selecting the 'p' option when using handin35 for the first time. Only one student in the pair should submit the lab.

You will earn reasonable partial credit for this lab if you complete and test your linked list implementation. So be sure to work in a modular fashion, testing and completing your linked list first before implementing the main program



Introduction

This lab is inspired by a late-90s internet phenomenon known as ASCII-mation (head here to see Star Wars as you've never seen it before). Most of you are familiar with ASCII art, where basic characters and symbols are pieced together to represent an image. ASCII-mation takes this a step further by placing a series of ASCII images one after another until it looks like a movie. In this lab, you will create a movie player that will load an ASCII-mation movie and allow a user to perform some basic functionalities including general playing features (playing, pausing, stopping, fast forwarding, and rewinding) and basic editing features (deleting scenes or reversing playback).

As mentioned above, you will represent a movie as linked list of frames. You will then use basic linked list operations to implement the basic functionalities listed above for a movie player/editor. Most of the file format/playing features have been provided for you. One frame of the image will look similar to the following:

31
                 -===                    `"',
                ""o o                    O O|)   Going somewhere,
                _\ -/_                  _\o/ _        Solo?
               /| || |\                /|\ / |\
              //| || |\\              //| |  |\\
             || | || | \\            // | |  | ||
             || |/  \|  \\        -==#  | |  | ||
             |! |====|   ')         '\  |====| /#
             =] |/|| |                  | || |  "
              I ( )( )                  | || |
                |-||-|                  | || |
                | || |                  | || |
________________[_][__\________________/__)(_)_____________________
We will represent the text for the frame as one large string. The value in the upper left-hand corner (e.g., 31) is to compress the file size. It represents how many frames in a row looked the same as this. The movie has been filmed at 15 frames a second, so a value of 31 means that this image appears on the screen for 31 frames, or just over 2 seconds.



Implementation details

Here, I list the requirements for each major component of the lab. See the IMPLEMENTATION STRATEGY section below for hints on how to begin attacking the problem.

You have been given the following files (blue indicates you will need to modify/implement in this file):

MovieList

I have provided a MovieList interface, very similar to the StringList interface given in lecture. A MovieList defines the normal list functionality, but adds remove (removes the data at position i) and a playFrom method specific to this task. Recall that the interface is not the implementation, so we could theoretically use either arrays or linked lists to implement a MovieList.

You must define and implement a MovieLinkedList class that implements the MovieList interface, without altering the MovieList interface.

MovieLinkedList (and its Requirements)

Don't worry about the movie-specific aspects at first; this class will largely be the same as any other linked list implementation. Begin by thinking about your algorithms in pseudocode and then implement them one-by-one. MovieLinkedList header file. Some requirements to note:

Main Player Program (and its Requirements)

Once you have thoroughly tested your MovieLinkedList implementation, you should implement the main program. The program has been started for you. To keep the program clean, we have divided the main program into three files. player.cpp only contains the main loop. Modify this to get it working, but any large implementation details should be done in the helper files. Those details should use good top down design (e.g., one function per feature). Any functions should be declared and defined in movie.h/.cpp respectively. We have provided getChoice() for you as an example. To complete the main program:

Take a look at getChoice() to see what options the user has. You should implement each option appropriately in the main while loop. These include: A couple pointers when implementing these methods:
An implementation strategy

You should always program incrementally such that you can test your work as you go. Here is one suggested strategy:

  1. Start by testing the FrameNode class in testLinkedList.cpp. Can you create a few nodes? Link them together? Print all the items? I have provided the beginning of a program to do this.
  2. Begin declaring the MovieLinkedList class in movieLinkedList.h. Remember that you must declare all data members and at least all methods specified in the MovieList interface before proceeding.
  3. Begin implementing your class in movieLinkedList.cpp. I suggest stubbing all functions (that is, defining the function and giving a dummy return value). This will let you compile the class properly without having done any actual implementation. An example function stub is:
    /* get - returns the value for the ith item in the list
       @param i, an int for the index of the frame to return
       @return a string containing a scene from the film
    */
    string MovieLinkedList::getFrame(int i){
    
      //TODO: implement this
     
      return "EXAMPLE FRAME";
    }
    
  4. Check to see if your class compiles, fix any errors before proceeding. Now, begin implementing one method at a time. I suggest starting with insertAtHead or insertAtTail. Your procedure should be: implement one method, compile, and then test it in testLinkedList.cpp
  5. Implement the destructor last. Carefully consider every possible way that your class might allocate memory on the heap, and be sure that there is a corresponding call to delete for each call to new.
At this point you should have a complete working MovieLinkedList class.

You should not under any circumstances begin the movie player implementation until you have thoroughly verified the correctness of your MovieLinkedList class. Any bugs in your MovieLinkedList class will hinder progress on the main program. Begin working on player.cpp by implementing and testing one feature of the program at a time. Be sure that your solution follows good design/modularity guidelines.


Tips and Hints

Throwing and Handling Exceptions

Your linked list should handle invalid usage by throwing a runtime_error. There is an example in the playFrom method in movieLinkedList.cpp as well is in the ArrayStringList implementation from class. For example, if you may want to handle an attempt to get an invalid item:

throw std::runtime_error("Attempt to get out of bounds");

Here is an example of handling a runtime_error (not required in this lab):

try{
  //do something dangerous
} catch (runtime_error& exc){
  cerr << "Warning: " << exc.what() << endl;
  cerr << "Ignoring illegal behavior." << endl;
}
Don't forget to include the stdexcept library when handling or throwing exceptions.

Submit

Once you are satisfied with your program, hand it in by typing handin35 at the unix prompt.

You may run handin35 as many times as you like, and only the most recent submission will be recorded. This is useful if you realize after handing in some programs that you'd like to make a few more changes to them. Only one partner should hand in the code for the lab.