CSCI 4230.1
Software Tools
Spring 2000
Mid-Term Examination

Name:  _________________________________

Time allowed: one hour and 20 minutes.
Open: text book, lecture notes, every file I posted in my web page and your project assignments.
Answer all five questions.  Turn in both questions and answer sheets.
Total score: 30%

(1)    [10%]  Write a Perl program t1aq1.pl, to show the counts of all biological quotes in a document.  Your Perl program accepts a file name as a command line argument.  A biological quote is of the format of "family vol,page".  "Family" can only be "Ani", "Ins" or "Pla".  Both vol and page are integers.  There may be spaces between the three fields.  Here are some examples of biological quotes:

Ani 101,201
Ins 98,111
Pla 6, 16

Note that a biological quote may span more than one line.  For the input file t1aq1dat.txt:

This is a quote, Ani 101,201.  Two more: Ani 101,201, Ani 101,333.
Three more: Ins 111, 202, Ins 111, 202, Pla 6,16.
Six more: Ins 111, 202, Ins 111,
201, Pla 6, 18. Pla 9,19,
Ani   101,201, Ani
101,202.

the output of executing

t1aq1.pl t1aq1dat.txt

is:

C:>t1aq1.pl t1aq1dat.txt
Ani 101,201: 3.
Ani 101,202: 1.
Ani 101,333: 1.
Ins 111,201: 1.
Ins 111,202: 3.
Pla 6,16: 1.
Pla 6,18: 1.
Pla 9,19: 1.

The following is a skeleton for you.  You only need to fill in the unfinished part:

use strict;
#   Read in input file data.
@ARGV < 1 && die "Error, usage: t1aq1.pl inputfilename.";
open(IN, $ARGV[0]) || die "Can't open file $ARGV[0].";
my @lines = <IN>;

my %counts = ();   #  Storing counts of quotes.

#   Populate %counts with input data.
#
#   FILL IN THIS PART HERE.
#

#   Print out %counts.
foreach (sort keys %counts) {
   print "$_: $counts{$_}.\n";
}
exit 0;

(2)   [2%]  Are there any error in the following Perl program?  If there is no error, what is the output of executing the program?

use strict;
my $ref = [{A => 1, B => 2},
           {A => 2, B => 1},
           {A => 3, B => 2, C => 1}];
my $contents = @$ref;
print $contents;
exit 0;

(3)   [10%] Write a CGI-Perl program, s00t1aq3.pl to access a MS Access database with DSN test through ODBC.  The database contains one table s00t1aq3.  The instances of the tables are shown below.

table s00t1aq3:

QuoteId   Family   Volume   Page   QCount
------------------------------------------
1         Ani      101      201    3
2         Ani      101      202    1
3         Ani      101      333    1
4         Ins      111      201    1
5         Ins      111      202    3
6         Pla      6        16     1
7         Pla      6        18     1
8         Pla      9        19     1

The program should return the total number of quotes for a given Family and Volume (specified in the URL).  For example, for the url

http://yourdomain/s00t1aq3.pl?family=Ani&volume=101

the output is:

For the url:

http://yourdomain/s00t1aq3.pl?family=Ani&volume=400

(4)    [3%]  Convert the following HTML code to use in-line style:

Whenever I <i><font color=#CCFFFF face=Arial>feel</font></i> blue, I eat an apple.

(5)    [5%]  Write a Javascript program to allow the user to enter a number and return its square and cube.  The GUI should be as below.  When a number is entered in the first box and the return key is hit, or the compute button is clicked, the next two boxes should be filled with the square and the cube of the integer.  No error handling is necessary.  For example, you don't need to worry about the user entering a non-integer.