The George Washington University
School of Engineering and Applied Science
Department of Electrical Engineering and Computer Science
CSci 51 -- Fall 1998
Project #9
Due Date: start of class, Thursday, 3 December 1998
Late projects accepted (subject to 20% fee) until 4 PM, 10 December 1998
in Chester Lund's faculty mailbox.

This project counts double, that is, as two projects

This project involves setting up a database for car records, similar to the one used by the State Department of Motor Vehicles. Attached is the source code for an interactive user interface program, proj_09ui, and the spec and body of a package cars.

proj_09ui, in operation, looks something like this:

Select one operation below:
 
C -> Table, Commit Table
R -> Table, Rollback Table
S -> Table, Select all Rows
T -> Table, Truncate Table
A -> Row, Add One Row
D -> Row, Delete One Row
F -> Row, Find a Row
U -> Row, Update One Row
Q -> Quit the Program
Please type a command, then press Enter > C   Thank you for correct input.

You'll find it easiest to do the project step-by-step, as follows:

Step 1: Compile these three programs and also the package simple_dates. Then link proj_09ui and run it, just to see how it behaves.

Step 2: Modify simple_dates according to the attached package spec. Use the concepts developed in Project 7.

Step 3: Implement the following task in proj_09ui:

database_writer

The database_writer task reads from input file into the DB_Commit array and the DB_Pending array. The database_writer writes only from the DB_Commit array (every so many seconds, you chose the time interval). We will provide a test data file cars.dat. You will be able to test these operations by running proj_09ui program.

Step 4: Now implement the operations

Commit_Database    --  Copy DB_Pending to DB_Commit
Rollback_Database  --  Copy DB_Commit to DB_Pending
Select_Database    --  Display all rows in DB_Pending

The database_writer task and the Commit_Database procedure require synchronization -- use the task synchronize_commit for this purpose.

Step 5: Now implement the operations

Put
Add_Row
Find_Row

so you can read in the data, add a few Add_Row transactions, then display and write the database to disk. You can then examine the disk file with vi or cat. Hint: Rewrite the Procedure Select_Database to use the Procedure Put.

Step 6: Complete the other operations in the database package and tie them into proj_09ui.

The Ada source code files necessary to start this project are stored in the directory "~csada/clund/proj_09". Use the Unix copy ("cp") command to obtain the files.

Here is the Simple_Dates interface with the desired modifications:

WITH Ada.Calendar;
PACKAGE Simple_Dates IS
------------------------------------------------------------------
--| Specification for package to represent calendar dates
--| in a form convenient for reading and displaying.
--| Author: Michael B. Feldman, The George Washington University
--| Last Modified: April 1996
------------------------------------------------------------------
 
  TYPE Months IS
    (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
 
  TYPE Date IS PRIVATE;
 
  PROCEDURE Get(Item: OUT Date);
  -- Pre: None
  -- Post: Reads a date ROBUSTLY in mmm dd yyyy form, returning it in Item
 
  PROCEDURE Put(Item: IN Date);
  -- Pre: Item is defined
  -- Post: Displays a date in mmm dd yyyy form
 
  PROCEDURE Get(File: IN Ada.Text_IO.File_Type; Item: OUT Date);
  -- Pre: None
  -- Post: Reads a date in mmm dd yyyy form from the given file,
  -- returning it in Item
 
  PROCEDURE Put(File: IN Ada.Text_IO.File_Type; Item: IN Date);
  -- Pre: Item is defined
  -- Post: Writes a date in mmm dd yyyy form to the given file
 
  FUNCTION Today RETURN Date;
  -- Pre: None
  -- Post: Returns today's date
 
PRIVATE
 
  TYPE Date IS RECORD
    Month: Months;
    Day: Ada.Calendar.Day_Number;
    Year: Ada.Calendar.Year_Number;
  END RECORD;
 
END Simple_Dates;