Question: For the final project, you will write a simple text-based command interpreter (a very rudimentary shell) in C/C++. The command interpreter is the component of
For the final project, you will write a simple text-based command interpreter (a very rudimentary shell) in C/C++.
The command interpreter is the component of the OS shell through which users issue instructions. With a text-based command interpreter, the user types a command in response to a prompt that appears on the screen. When a command is entered by the user, the command interpreter determines what the command means (interprets it) and then executes it.
Your command interpreter should do the following.
Display a prompt for the user.
Read the user's input.
Determine if the entered command is valid
If it is valid, executes it and then re-display the prompt.
If the command is not valid, display a specific, appropriate error message and re-display the prompt. Be sure that your command interpreter differentiates between different errors that render a command invalid.
Continue until the user enters the command QUIT.
The valid commands will be
RUN executable-file
LIST
LIST directory
COPY old-filename new-filename
CD directory
SHOW file
HELP
QUIT
Notice that some commands have no arguments, some have one and some have two and so your interface must handle a variable number of parameters.
Phase 1: Command Line Parser
Electronic Copy Due: Tuesday, December 8, 2015 (Electronically submitted by 10:00 PM)
Hard Copy Due: Wednesday, December 9, 2015 at the beginning of class.
Write a C++ function called parse that reads one line of user input from the keyboard and creates an array of the strings found in the input. Your function should be passed the array and a reference variable that is to be assigned the length of the array. Prompt the user and read the input from within the function.
For example: If the user inputs cp this that, the resulting array would have length 3 and contain the strings cp, this, and that.
Create a main function that has a loop that will continuously call the function until the user enters the string quit. After the function has returned control to main, print the contents of the array and its length.
Your program should:
Give detailed directions to the user.
Contain carefully worded pre and post conditions for the parse function.
Be readable with appropriate documentation and formatting.
Use an array of cstrings.
Read the users input one character at a time using cin.get().
You will need to build the strings one character at time using white space to separate the strings. (Remember that cstrings end in \0.)
DO NOT USE getline() !!!
Skip any extra whitespace within the users input or at the end of the input
copy this that and copy this that would produce the same result.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
