Importantly, issuing multiple undo operations in a row should continue to undo changes made to the document, and issuing multiple redo operations in a row should continue to redo changes to the document. This is called multilevel undo/redo, as opposed to one level of undo/redo.
When a blank line is entered by the user, the program should terminate. After each time the user presses enter, the document as it currently stands should be output to the screen, and the user should be prompted for the next command. Your code must be robust in the sense that it should not be possible to crash the program (for example, by trying to delete a non-integer line or a line that does not exist, or trying to pop empty stacks or queues).
Here's an example of program execution.
Command?first ['first'] Command?second ['first', 'second'] Command?third ['first', 'second', 'third'] Command?d Delete which line?2 ['first', 'third'] Command?fourth ['first', 'third', 'fourth'] Command?undo ['first', 'third'] Command?undo ['first', 'second', 'third'] Command?redo ['first', 'third'] Command?Implementing the undo/redo functionality should be achieved using one or more stacks or queues (part of the assignment is figuring out what to use here!). In particular, you should ask yourself the following questions:
For this part of the assignment, you should submit a Python code file that we can run to interact with your editor from the keyboard. You should also submit a file showing various tests of your editor that lend proof to your code working properly. Also, remember to comment your code. In particular, you should include a high-level description of how your implementation works.
In this part of the assignment we will continue to practice using (1) lists, (2) classes and (3) exceptions. (Yes, exceptions really are classes, but I really wanted to have three points there.) You are to implement a class called LetterManager that can be used to keep track of counts of letters of the alphabet. The constructor for the class takes a String and computes how many of each letter are in the String. This is the information the object keeps track of (how many a’s, how many b’s, etc). It ignores the case of the letters and ignores anything that is not an alphabetic character (e.g., it ignores punctuation characters, digits and anything else that is not a letter).
Your class should have the following methods:
You should implement this class with a list of 26 counters (one for each letter) along with any other data fields you find that you need.
Once you have created this class, use it to write an Anagram Checker program. This program will prompt the user for two words and report whether the two words are anagrams of one another. Two words are anagrams if they both include the same counts for all their letters. (In other words, one word is just a "scrambled" version of the other.) For example, horse and shore are anagrams since they each include one copy of the letters E, H, O, R and S.
For this part of the assignment, you should submit three Python files: a file that contains your letter manager class, a file that uses your letter manager class to test whether two words are anagrams of one another, and a file containing test cases for both of these parts. Be sure that your tests are comprehensive and test boundary cases, typical cases and atypical cases.
Sometimes it is convenient to do more with a stack than push and pop the top element. In fact, some computer architectures and programming languages are built around using the stack to drive program execution, so more powerful primitives often make the programmers' life easier. For example, if you are writing a sorting program and all you have available is a stack, it would be helpful if you could swap the top two elements on the stack.
In this part of the assignment, you'll write two higher-level functions on stacks whose implementations are based on the stack primitives (push, pop, and so on). Your functions should work on stacks created with the stack classes of stack.py. Download the starter code stackops-template.py which includes two functions whose bodies you are to fill in. The first, swap, is designed to swap the top two elements of a stack. For example, if a stack contains the string red at the top of the stack, and the string blue below it, a swap will result in blue at the top and red beneath it (the rest of the stack is unchanged). The roll operation is designed to take an integer n along with the stack. We can define roll operationally as follows. First, pull out the nth item from the top of the stack (the top of stack is item 1; the item below it is item 2, and so on). Second, push this removed item onto the top of the stack. For example, consider the stack "1 2 3 4", where the left end is the bottom of the stack and the right end is the top (so the number 4 is at the top of the stack). A roll 2 will yield "1 2 4 3" and a roll 3 will yield "1 3 4 2".
For this part, you should submit the Python file where you have filled in the function bodies. You should include test cases as well to show us that your stack functions are working properly.