Assignment #1, COP-3337

This assignment is due on Tuesday, January 21 at the start of class.

General Problem

You are to write a program that will search a file and report when a particular class is being offered. You will list all sections.

Details

An (old version of the) Spring 1997 schedule is in the file /home/s_95a/mweiss01/www/spr1997.txt. on serss1 and /fiu/aul/mongoose/2/weiss/cop3337/mweiss01/www/spr1997.txt. on mongoose You can view its contents by going there directly (you can use ~mweiss01 as a shortcut, but not inside a C++ program), or you can view it from Netscape at http://mongoose.aul.fiu.edu/~mweiss01/spr1997.txt. This program is different than usual, because the C++ program will be used to get information from a form request that will be submitted to the Netscape browser.

The Form

First you will need to generate a form. This has nothing whatsoever to do with C++. To generate a form in Netscape, you have to write a little HTML code. Non-programmers do it all the time, so I assume you can too. If you do not know HTML, the easiest way is to find a page that contains some HTML and then view the source. Netscape has menu items (view frame source or view document source) for this (this is at the top menu bar). You can see a more complicated form than what you will actually need by going here.

Processing the Form

When the button is clicked, a program is invoked. In the example above, the program is program1.cgi. This is the executable code of a C++ program (any language could be used; Perl and shell scripts are more popular). It is the C++ program that you must write. The entire program will be very short, because you will use a package that I will supply.

Finishing Everything

When you are ready for a demo, do the following:
  1. In your home directory, create a subdirectory named www. It must not be read or search protected (make it mode 0755, using chmod).
  2. In the www directory, create an html file. This must be accessible (make it mode 0644).
  3. When you have compiled your C++ program, it must be place in the www directory, with suffix .cgi and executable (make it mode 0755).

Writing the C++ Program

You will need the following files: Exception.cpp, Exception.h, String.cpp, String.h, Vector.cpp, Vector.h, PostForm.cpp, PostForm.h. All of these are in this directory. You can download or copy from ~mweiss01/cop3337/prog1. String is a class that I have written that provides decent strings (as opposed to the array of character version that is supplied with C++). Note that it includes a string concatenation operator that is not in the online source code found elsewhere. So use this version for now! PostForm is a class that can be used to extract information about what has been selected in the form. (What actually happens is that the program will see a line of input of the form Name1=Val1&Name2=Val2&Name3=Val3 and so on representing the data in the form fields; the PostForm class simply parses these lines). You do not have to know how these work; you just need to know that they do (more or less).

A Sample Program

The best way to see how PostForm is used is to look at program1.cpp, which is the program that processes the form shown earlier, and outputs the maximum of the two entered values. The other classes will not be used directly by you (yet), but are part of the PostForm implementation. What program1.cpp does is get the input values from the form and then write output. There is an initial two lines of output (a content type line and a blank line) that must always be output. You can see the exact output of the program by doing the following:
cd ~mweiss01/www                   (Go to my www directory)
program1.cgi                       (Execute the C++ program)
val1=5&val2=7                      (Simulate the input of 5 and 7)
^D                                 (Signify the end of input)
(in this code, the last line is the control-d sequence, and the prior line is a line of input that could be generated by a form). The output will be simple HMTL code. Check it out!

Doing It

Once you've written your C++ program, compile all the .cpp files (but not the .h files) with
CC *.cpp
Remember that you will need to move the a.out to your www directory, rename it, and make it more accessible. Cheap trick: Create a link (using ln) so that your a.out and renamed program in www are really the same file. This will save you from continual copying.

I'll talk about this in class, but for the most part, this assignment is about using other people's code. After some normal trial and error (which may be a little frustrating for a while), you should eventually get a working program.

Hint

Download the samples, compile them, and install in your www directory. Make sure you can get that to work before proceeding with your own program.

What to Submit

Submit a well-documented and commented C++ program that includes a disclaimer stating that the work is your own. Also print out the Netscape windows showing the form and the results (Netscape has a print button).