COP3832, Fall 2000, Assignment 4
Due Monday 11/8 at the start of class.
To hand in the assignment, do the following
-
Hand in a printout of the source code for the hw4.pl file.
-
Upload a copy of the hw4.pl file using the
~downeyt/cshome/public/webftp/webftp.pl program from mongoose.
It is imperative that you do not allow anyone else to have access to the
hw4.pl file.
Create a Perl script on mongoose named hw4.pl that is run from
the command prompt, not from the web. The script should do the following:
-
Include the -wT switches to the Perl command.
-
Use strict.
-
Use POSIX. This will include the functions ceil and floor.
-
You may not use global variables (local), use my variables
. Use functions to organize your code, pass any parameters. You must have
at least three functions: read the data; calculate the total, min, and max;
display the table, min, max, size, total, and average.
-
Read an unspecified amount of integers from the user. Continue reading integers
from the user until a negative integer is entered. Integers must be entered
one per line. If a non-integer is entered, then print a message and read
a new value. Do not place non-integers into the array. (Hint: use a regular
expression to extract the digits from the input). Don't forget to remove
the trailing new-line character from all input lines.
-
Display all the numbers entered in a table. Do not include the terminating
negative number. The table should be square, that is it should have the same
number of rows as columns. Use the smallest square table possible to hold
all the numbers entered. It is possible that the last row (or rows) of the
table will have some (or all) empty cells. Display an asterisk in empty cells.
-
Display the count, total, and average of all the numbers. Round the average
to two decimal places.
-
Display the largest number and its location in the list of numbers that were
entered.
-
Display the smallest number and its location in the list of numbers that
were entered.
-
Error checking is required. I will test your programs extensively. Be sure
that garbage is never displayed, and that the script never crashes.
Some useful functions in Perl
-
sqrt
-
ceil (part of POSIX)
-
floor (part of POSIX)