COMP 104 : Programming

Lab 10: Star Wars movie player


In Lab10, you will write a program that simulates a movie player. Your program will read in a text file containing ascii frames from the movie Star Wars, and store the frames in a doubly linked list.

Here are some text files you can use to test your movie player: scene1.ani, scene2.ani, scene3.ani, starwar.ani (1.8Mb, just for fun if you have finished the lab assignment)

Each text file should end with a new line.

Your program must implement the following functions:
    1. play forward
    2. play backward
    3. pause
    4. stop
    5. delete current frame
    6. duplicate current frame

The file i/o, player menu, and player control functions are given to you, so that you can focus on the doubly linked list part. You may modify the given functions. Here is the skeleton of the program. You may modify the skeleton, but it's always good to build up a large program from small pieces.

Requirements:

  1. Except for constants, your program should not use global variables.
  2. You should use a doubly linked list to store the frames.
  3. Your program must not have any memory leaks or dangling pointers.
  4. Use the following structure (note that it is a user-defined data type, not a variable):
    struct Node{
        string frame;
        Node* next;
        Node* prev;
    }

    typedef Node* NodePtr;

    Each frame is a string in this form.


    Function explanation:

    To start the program, the user must first input the full file name.

    There are totally 7 functions you must implement in the skeleton.

    1. void append_frame(NodePtr &Head, NodePtr &Rear, string nframe);
      This function allocates a new node with its frame set to nframe, and appends the new node to the end of the doubly linked list. Head points to the first node in the linked list, Rear points to the last node in the linked list, and frame is the data frame to be appended. (This function is called in the load_tape() function.)
    2. void play_forward(NodePtr &ptr);
      If ptr is NULL, just output "no more forward". Otherwise, move ptr one step forward if there is a node and display the frame. Otherwise, leave ptr unchanged, display the frame and output the message "no more forward". example.
    3. void play_backward(NodePtr &ptr);
      If ptr is NULL, just output "no more backward". Otherwise, move ptr one step backward if there is a node and display the frame. Otherwise, leave ptr unchanged, display the frame and output the message "no more backward". example.
    4. void copy_frame(NodePtr &ptr);
      Copy the frame pointed to by ptr (if ptr is not NULL) into a new node and insert it as the next node after ptr. Do not change the value of ptr.
    5. void delete_frame(NodePtr &Head, NodePtr &ptr);
      Delete the frame pointed to by ptr (if ptr is not NULL). Then if there is a node after it move ptr one step forward, otherwise if there is a node before it move ptr one step backward, otherwise simply output the message "no more delete". After moving ptr, output the frame it points to if it exists. example.
    6. void stop(NodePtr &Head, NodePtr &ptr);
      Set ptr to Head and output the first frame.
    7. void erase_tape(NodePtr &Head);
      Remove the entire doubly linked list to free up the memory.

     

    Hints:

    Implement the append_frame(), play_forward(), and play_backward() functions first to ensure the movie playback has no problems.

    Be careful to avoid dangling pointers, always check to see if a pointer is NULL or not before accessing the element it points to. It is good to set the pointer to NULL if it has nothing to point to.


    Demo your working program for your TA. If for some reason you cannot finish before the end of the lab period, email your program to your TA by Sunday 27 November 5PM (please include your name and lab section as a comment on line 1 of your program).