L548: Final Exam

Notes:
a) Send the exam to upriss@indiana.edu by Monday, December 10, 12.00 pm (Noon).
Send 2 scripts as attachments to an email message. The 2 files should be labeled yourname1, yourname2. All files must be normal, uncompressed text (no MS Word documents!!!).
b) You will get a better grade if you produce programs that run without errors but do not have all required features than if you work on all the features but your programs cannot be executed.
c) The scripts must be completely written in Perl. System calls to Unix utilities or other programming languages are not allowed.
d) Team work is not allowed. If you have questions, send them to upriss@indiana.edu. If the question can be answered without giving too much help, the answer will be posted to the class mailing list.
e) No libraries or subroutines other than the standard ones should be used (i.e. the scripts should not have a "use ..." statement).

1) A calendar tool

Write a script that lets a user maintain a calendar/schedule for December 2001 - April 2002. Store the data needed to create such a calendar in arrays (don't use the Perl or Unix date or calendar functions!). Think of a way to store the information efficiently.

The information to be stored for every day is: day, month, year, day of the week (Monday, Tuesday, ...) and appointments. Appointments should be stored as one string per day. Several appointments for a single day should be concatenated into one string.

The interface to the calendar must be from the Unix command line (no CGI). At the beginning the user is asked whether he/she would like to print the information for a specific week or whether he/she would like to enter new appointments.

In the first case, the user is asked to type in day/month/year. Then the week (Monday through Sunday) which contains that day is printed with all its information in some kind of tabular format.

In the second case, the user is asked to type in day/month/year If the day already contains an appointment, the user is given the options to either delete the old appointment, replace the old appointment with a new one or to add a new appointment. If there is no old appointment, the user is only asked to enter the new appointment.

In both cases, the script then starts over by asking the user whether he/she would like to print the information for another week or to enter more appointments. A third option at this point is to exit the program. The script should only stop if the user selects "exit" at this point, otherwise it should keep running.

Note: it is not necessary to store any of the information in a file. That means that all appointments will be lost once the program stops.

2) Search

Write a script that reads a file called input.txt (eg the alice.txt file) and asks a user to type in two words (or phrases).

First, the script checks that the words do not contain any unusual characters apart from word characters, any kind of blank space, or a hyphen. If an unusual character occurs, the script should stop (or die).

Then the script searches the file for the words. It outputs the following information to a file called output.txt:

How often each of the two words occurs in total.
How many lines contain at least one of the two words.
How many lines contain both words.
How many lines contain none of the two words.