关键词 > CS20A

CS 20A: Data Structures with C++ Project 4

发布时间:2024-05-27

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 20A: Data Structures with C++

Project 4: Doubly Linked List and Movie Player

Due: 5/31/2024 @ 11:59PM

Goal

In this project, you will implement a doubly linked list collection. Once you have it working, you will then simulate an old-fashion reel-to-reel movie player.

Setup

•    Be sure to follow the setup guide on Canvas.

•    You should read this writeup in its entirety before writing any code. The details about doubly linked lists are scant in the writeup – check the lecture on linked lists for more details about   each function.

•    The assignment has an interactive mode and a testing mode. Running main generates a user

interface with the GTerminal. Check later in this document for how to work with the object. You are to write the tests for all your code. The graded tests are run with Travis when you push your code to GitHub. These tests not only thoroughly test the linked list and movie player functionality – they also check for memory leaks.

•    For this project, you will be editing main.cpp, SMCList.hpp, movie.h/cpp.

•    All functions you’re to complete are currently stubs – they have just enough code for the

program to compile and run – though the results aren’t correct. Several places there are TODO comments – this is where we recommend you fill in your code.

•    For this project, do not modify the function names, return types, or parameters of any of the functions. We will be testing your code using automated testing programs, so changing these will result in an automatic deduction.

Part 1: SMCList

•     In this part, you will implement a templated doubly linked list in SMCList.hpp.

Note that although many other online references list implementations for a doubly linked list, do not just directly copy such code, or there will be a severe penalty including being reported for academic dishonesty.

•    Beyond the standard doubly linked list functionality, your list should also implement an iterator to the list to keep track of a position in the list. There are functions to for the iterator as well as  removing and adding at an iterator’s position.

•     The following is already provided for you, and should not be changed:

o  Node struct

o  Member variables inside of SMCList (mSize, mHead, mTail)

o  Default Constructor

•     Each of the functions below need to be implemented by you. Each function has the pseudocode outline of its logic covered in lecture. You should follow this very closely to ensure your functions are correct. It is also recommended you implement them in this order:

1.    Default constructor

2. size Returns the size of the list

3. Output stream operator (<<)

4. toString and toReverseString

5. push_front Insert to the front of the list

6. front – Get the value at the front of the list

7. pop_front Remove the value at the front of the list

8. push_back – Insert to the back of the list

9. back – Get the value at the back of the list

10. pop_back Remove the value at the back of the list

11. clear – Removes everything from the list

12. Destructor

13.Copy Constructor – Constructs the list as a copy

14.Assignment Operator Equals operation

15. Iterator Basics – Creating iterators (including begin, end, and constructors) and dereferencing iterators

16. Iterator Traversal Moving forwards/backwards with an iterator

17. insert Using an iterator to insert into a list

18.erase – Using an iterator to remove from a list

•     The there are several tests for each function and some functions are used in many tests. As you complete the list, more and more tests will pass – especially if you follow the above order.

•    Furthermore, before you implement the destructor, you will get an error message regarding

memory leaks. Once you implement all the functions, you should no longer get the memory leak error message. If you do, make sure your deletes appear in the right spots.

Part 2: MoviePlayer

•    Now you’ll implement a movie player. The movie player simulates an old fashioned reel-to-reel film player that can go backwards, forwards, and splice scenes from the film. This is identical to the previous assignment, but I’ll repeat the notes here, just in case.

•    To generate animation a series of frames will be displayed on the screen. Each frame should

ideally appear on the screen for about 40 to 60ms (this number can be changed by user input). We’llcall this the “display time” to indicate how long each frame will be displayed.

•    Movies come in the form of plaintext files. Each file is made up a series of frames. Here’s a breakdown of the format for each frame:

1.    Each frame begins with a “separator” line. This line has only a number in it. This

indicates how many long the frame should be shown. For example, if a separator has the number “7” then the following frame should appear for 7 x “display time” in milliseconds. This separator line should not be displayed to the screen.

2.   The following 13 lines (or FRAME_SIZE) in the text file make up the image (or frame) to display.

3.   The next line is the separator line for the following frame

4.    Be sure to examine the film files (they’re the text files that end with the suffix “.ani”). Any text editor should be able to open them. Be sure not to change them!

•    If you open up movie.h/cpp you’ll see some code already provided to you.

There are 5 member variables:

1.   A const unsigned that stores the number of lines in a frame. You can use this to iterate through the movie files.

2.   An SMCList of strings that are each a frame of 13 lines of text. I’ll often call this “the tape” in this document.

3.   An Iterator for the above structure to track where you are in the tape.

4.   A string that has the name of the text file that stores the movie file.

5.   An unsigned that holds the current frame number, or the position the viewer is seeing in the movie. Be sure to keep track of this variable as you manipulate the tape!

•    You must implement all 12 member functions for the MoviePlayer class:

1.    MoviePlayer constructor: The parameterized constructor should set the appropriate member variables, ensure that the tape is empty, then call the member function loadTape on the inputted file name.

2.    MoviePlayer destructor: While not necessary, we’ll protectively ensure that the tape is empty here.

3.   The rewind function: Here you’ll start the tape over again, being sure to keep track of the currFrameNum counter.

4.   The loadTape function: This function should open the inputted text file. Assume the    user only enters one of the “.ani” files. This function parses out the text file, makes up the frames, and fills the SMCList with the animations.

5.   The goFwrd function: This function should move the tape forward 1 frame. It should also increment the currFrameNum counter.

6.   The goBack function: This function should move the tape backward 1 frame. It should also decrement the currFrameNum counter.

7.   The getCurrFrameNum function: Here you’ll return the current currFrameNum counter.

8.   The delCurrFrame function: This function will delete the current frame and move the tape forward 1 frame.

9.   The copyCurrFrame function: This will copy the current frame and move the tape to the newly added frame.

10. The getNumFrames function: Here you’ll return the total number of frames in the movie.

11. The getFrameSize function: This function gets the number of lines in a frame.

12. The getCurrFrame function takes in no input and returns a string with the contents of the current frame.

•    You will also need to update the getCurrFrame function in main.cpp. It takes in a GTerminal and a MoviePlayer both passed in by reference. Using the clear and appendText functions of GTerminal, add the lines of text from MoviePlayer’s getCurrFrame to the terminal.

•    When asked to play a movie, main will prompt the user for a text file name and delay time. It

will then create the GTerminal user interface, create the MoviePlayer’s. The user interface can play the movie forward and backwards. It can also pause the movie, copy the current frame and remove the current frame. The entire solution uses the SMCLib for user interface and graphics.

•    While moving through a tape, be sure to check that you’re not trying to move past the beginning or end of the tape!

•    To eventually showoff the solution to your friends, on Windows you can start without debugging either through the pull-down menus or by hitting CTRL + F5.

Hint: There are shorter input files (scene1.ani, scene2.ani, and scene3.ani). Try these while

testing your program. You should test to make sure you’re able to successfully reach the end of the tape and beginning of the tape with no errors.

Hint: Some input files have problematic input. In particular,a line may end with a backslash “\” . This can be a problem. You can try getting around by adding a space character to the end of the string ending in the backslash.

Hint: Some input files have other pieces of problematic input. Make sure that if the file ends with a partial frame or something like that you don’t add it to the linked list.

Hint: Some input files have a few empty frames. These may just be empty lines. Be sure your code detects empty lines appropriately in the loadTape function.

•     A successfully implemented Part 2 should look like the following (user input in red). Since the movie involves about a third of the original film here’s only a few screens of output (user input in red).

Input file: input/starwar.ani

MS delay between frames: 60

•    Movie screen before movie plays:

•    Movie playing:

And …

Submission

You must push your code to the GitHub assignment to submit your solution.

Grading

Item Points

SMCList (graded unit tests)

62

MoviePlayer (graded unit tests)

10

Overall quality of student unit tests

18

Overall code quality

10

Total 100