CSPS 335 Perl CGI Programming

Assignment 2 (Spring 2002) - Simulating a Simple Calculator

Primary Objectives of the Assignment
  1. Simulating a calculator with form elements
  2. Sending encoded form data from the browser to the server
  3. Creating a CGI script for processing form data and
    regenerating the calculator page
Part A -- Simulating a Simple Calculator (calculator.html)

Using an HTML form, simulate a simple calculator similar to the one shown in
the figure.  The calculator page should have the following form elements: Part B --Writing A Perl CGI Script (calculator.cgi)

Write a Perl CGI script called calculator.cgi to process the decoded form data
and outputs HTML code to regenerate the calculator with the result.  The first
three statements in the calculator.cgi script should be:
  #!/usr/bin/perl
  require "subroutines.lib";
  &Parse_Form_POST;

Part C --Creating A Subroutine Library (subroutines.lib)

This subroutine library file, called subroutines.lib, is to contain some frequently
used subroutines.  In this assignment, the Parse_Form_POST subroutine in
subroutines.lib will be called by your calculator.cgi described in Part C.  The
Parse_Form_POST script parses the encoded form data sent from the browser
and stores the decoded data in %formdata hash as key-value pairs.
The NAME-VALUE attribute pairs in the HTML form should correspond to the
key-value pairs in %formdata.  The Parse_Form_POST subroutine can be
found at http://cs.selu.edu/~jhu/parseFormCGI.html.

Note:
When the Submit button is clicked, the data on the form is sent to the server
in one long stream of name-value pairs.  Each name-value pair is separated
from the next by an ampersand as shown in the following example:
     number1=48&operator=mul&number2=7   

Example of a simulated calculator
Click Here to see an actual example of this assignment
Click the Back button on the toolbar to return to Home Page