Project 3
Spring 2002
Due: Wed., Mar 27 @ 5 PM
9 points
You've always been into the retro thing, and you're now convinced that the trend of mouse-driven, GUI operating systems has run its course. Command-line interfaces will soon be back in vogue, and in preparation for this propitious event---and to position your product in the marketplace---you've decided to start writing a new operating system, code-named ``pos'', which among other things, stands for ``plebe operating system.'' Needless to say, the commands of pos will be loosely based on UNIX. Market research suggests that most people like names for operating systems with three letters rather than four.
At this point in your nascent programming career, you're probably best equipped to deal with commands that manipulate files, so begin by writing functions that implement commands for copying files (i.e., the copy command), for printing a file's contents to the screen (more), for searching a file for string (grep), for counting the number of words in a file (wc), and for counting the number of lines in file (lc). You'll also need commands for printing a help screen (help) and for leaving the command shell (exit).
The syntax for the commands should be:
The commands will operate on text files in your directory, and the way the commands work should be intuitive. copy should copy the contents of a file named <source-filename> into a file named <target-filename>. more should print the contents of a file named <filename> to the screen, pausing after each set of 24 lines. grep should print to the console the lines of the file <filename> that contain <string>. wc and lc should count the number of words or lines, respectively, in the file named <filename> and prints this count to the console. help prints to the console a list of commands, their syntax, and a brief description. exit leaves the program.
Naturally, the program should check if files exist, issuing an appropriate error message, if necessary. You can assume that users will always type the appropriate number of arguments, although you might want to think about how to parse the command line to determine if the user typed the appropriate number of commands.
Here is a sample run. The user's command are set in bold.
You should write a function for each command. You can put the command loop in either main or a separate function. In addition to header comments at the top of the file to document the program, you should place comments above each function that ocuments the function's purpose. You should also document any tricky sections of code, but for this project, most should be straightforward.
Instructions for Electronic Submission: At the top of the file containing your source code (i.e., the file containing the C++ instructions), place the following header comment, with the appropriate modifications:
// // Project 3 // Name: <your name> // E-mail: <e-mail address> // Instructor: Maloof // TA: <TA's name> // COSC 071 // // In accordance with the class policies and Georgetown's Honor Code, // I certify that, with the exceptions of the lecture notes and those // items noted below, I have neither given nor received any assistance // on this project. // // Description: <Describe your program> //
Although you may use any C++ compiler to develop your program, it must run under UNIX and must compile using GNU g++. When you are ready to submit your program for grading, if necessary, use ws-FTP to transfer your source and data file from your PC to gusun. Use SSH to logon to gusun, and use pine to e-mail it to your TA. Use your netid and the suffix ``.cc'' as the subject.
gusun% pine
When the menu appears, select the item for composing e-mail. Assume that your netid is ab123, the name of your source file is proj1.cpp, and your TA's e-mail address is ``imagoodtamaloof@cs''.
Type your TA's e-mail address in the To field, and type your netid with the .cc suffix in the Subject field (no spaces before or after). Move the cursor down into the MESSAGE TEXT screen, and type the ^R command. Pine will ask for a file name (e.g., proj1.cpp), which it will then load as your message text. At this point, your screen should look something like the following:
Finally, type ^X to send the e-mail to your TA.
IMPORTANT: Do not send your source code as an attachment. Do not use a mail client other than pine.
If you need to include a message to you TA about your submission, then type the message as a comment in the program.
Once you've submitted your project, it is important to keep an electronic copy on a university machine (e.g., gusun or cssun) that preserves the modification date and time. If we lose your project or the e-mail system breaks, then we will need to look at the modification date and time of your project to ensure that you submitted it before it was due.
The TAs who will be grading your projects this semester are listed on the main page. You must e-mail your project before 5 PM on the due date.