|
| Budget: |
$ 20-100 |
| Status: |
Closed
for Bidding (selected
user dynamic03bd)
|
| Project
Creator: |
|
| |
        
3
reviews
|
| Required
Skills: |
|
| Attached
Files: |
(None) |
 |
|
|
|
|
|
|
|
|
|
|
Description
You are required to implement a simple command prompt for manipulating an ordered list of numbers. In completing this project you will need to exploit the concepts of stacks, queues, and searching.
At their core, a command prompt will display a prompt to the user and process the commands that they type in. The commands that you are required to implement for this application are all single word commands, as follows:
* add - prompts the user for a number and stores that number in the ordered list; * remove - prompts the user for a number and removes that number from the ordered list (if it is present); * show - display the current contents of the ordered list;
* exit - terminates the program; * help - displays a list of the valid commands; * history - displays the most recent commands;
* undo - undoes the last add/remove command; and * redo - redoes the last command undone (if any).
There are no restrictions on how you implement the above functionality, beyond the following points:
1. The standard C++ programming language must be used, you may not use any kind of library or example code for a command prompt application; 2. Any STL type/s can be used in accomplishing the required functionality; 3. A queue of some description must be used for the command history; 4. Stacks must be used for the undo and redo commands; and 5. Duplicates are not permitted in the list.
The tasks listed below provide further information/requirements. You do not need to strictly follow the order of these questions. Below the questions is an example run of such an application to allow you to see the final solution in operation. Your output does not need to match this example, but it must be reasonably intuitive.
The following main function may help you to get started (you do not need to use this however):
int main(int argc, char *argv[]) { string input;
cout < \"; cin >> ws >> input; while(input != \"exit\") { if(input == \"add\") { /* code to handle add command */ } else if(input == \"help\") { cout << \"Commands:\" << endl; cout << \"\tadd exit help history\" << endl; cout << \"\tredo remove show undo\" << endl; } else if(input == \"history\") { /* code to handle history command */ } else if(input == \"redo\") { /* code to handle redo command */ } else if(input == \"remove\") { /* code to handle remove command */ } else if(input == \"show\") { /* code to handle show command */ } else if(input == \"undo\") { /* code to handle undo command */ } else { cout << \"Invalid command.\" << endl; }
cout < \"; cin >> ws >> input; } }
TASK 1
Implement the functionality for the add, remove, and show commands. Remember that duplicates are not permitted.
TASK 2
Implement the command prompt history and the history command, remembering that a queue must be used for this purpose. The following notes provide information and requirements:
* When a command is entered it is enqueued in the queue. Note that all commands should be stored in the list, regardless of whether they are valid or not, or succeed or not; * The history must be limited to 10 commands.
TASK 3
Implement the undo and redo commands. For this purpose, you will need an \"undo stack\" and a \"redo stack\". The operation of these stacks is as follows:
* When an add or remove command is successfully completed, an entry is pushed onto the undo stack recording the operation; * When the undo command is entered, if there is anything on the undo stack it is popped off the stack and the recorded operation is undone; * Whenever an operation is undone, an entry is pushed onto the redo stack recording the operation; * When the redo command is entered, if there is anything on the redo stack it is popped off the stack and the recorded operation is redone; * Whenever an operation is redone, an entry is pushed onto the undo stack recording the operation; and * Whenever an add or remove command is successfully completed, the redo stack is cleared.
Consider the following example which illustrates the ordered list, undo stack, and redo stack, throughout the operation of the following commands:
1. add 5 2. add 10 3. add 12 4. undo 5. undo 6. redo 7. redo 8. undo 9. remove 10 10. undo 11. add 15
Initial state:
List:
Undo stack:
*
Redo stack:
*
After add 5:
List: 5
Undo stack:
* add 5
Redo stack:
*
After add 10:
List: 5, 10
Undo stack:
* add 10 * add 5
Redo stack:
*
After 'add 12':
List: 5, 10, 12
Undo stack:
* add 12 * add 10 * add 5
Redo stack:
*
After undo:
List: 5, 10
Undo stack:
* add 10 * add 5
Redo stack:
* add 12
After undo:
List: 5
Undo stack:
* add 5
Redo stack:
* add 10 * add 12
After redo:
List: 5, 10
Undo stack:
* add 10 * add 5
Redo stack:
* add 12
After redo:
List: 5, 10, 12
Undo stack:
* add 12 * add 10 * add 5
Redo stack:
*
After undo:
List: 5, 10
Undo stack:
* add 10 * add 5
Redo stack:
* add 12
After remove 10:
List: 5
Undo stack:
* remove 10 * add 10 * add 5
Redo stack:
*
After undo:
List: 5, 10
Undo stack:
* add 10 * add 5
Redo stack:
* remove 10
After add 15:
List: 5, 10, 15
Undo stack:
* add 15 * add 10 * add 5
Redo stack:
*
Example Run
Below is an example run of a solution to the above project using a similar sequence of operations to those used in the example in Task 4. The show command is used throughout to show the contents of the ordered list and the count of elements in both stacks. The other commands are also demonstrated in the script. The \"command prompt\" used in the solution is a simple greater-than symbol (>). User input has been highlighted in red.
> help Commands: add exit help history redo remove show undo > show List: Undo stack: 0 entry/entries Redo stack: 0 entry/entries > add Number> 5 Succeeded. > show List: 5 Undo stack: 1 entry/entries Redo stack: 0 entry/entries > add Number> 5 Failed. > show List: 5 Undo stack: 1 entry/entries Redo stack: 0 entry/entries > add Number> 10 Succeeded. > show List: 5 10 Undo stack: 2 entry/entries Redo stack: 0 entry/entries > add Number> 12 Succeeded. > show List: 5 10 12 Undo stack: 3 entry/entries Redo stack: 0 entry/entries > undo Succeeded. > show List: 5 10 Undo stack: 2 entry/entries Redo stack: 1 entry/entries > undo Succeeded. > show List: 5 Undo stack: 1 entry/entries Redo stack: 2 entry/entries > redo Succeeded. > show List: 5 10 Undo stack: 2 entry/entries Redo stack: 1 entry/entries > redo Succeeded. > show List: 5 10 12 Undo stack: 3 entry/entries Redo stack: 0 entry/entries > undo Succeeded. > show List: 5 10 Undo stack: 2 entry/entries Redo stack: 1 entry/entries > remove Number> 10 Succeeded. > show List: 5 Undo stack: 3 entry/entries Redo stack: 0 entry/entries > undo Succeeded. > show List: 5 10 Undo stack: 2 entry/entries Redo stack: 1 entry/entries > add Number> 15 Succeeded. > show List: 5 10 15 Undo stack: 3 entry/entries Redo stack: 0 entry/entries > some_invalid_command Invalid command. > history History: undo show remove show undo show add show some_invalid_command history > exit Press any key to continue . . .
Reminder
You may not start working in this and any project before
your bid is accepted. Any user who violates this policy
may have their account permanently suspended.
|