
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, Cars_UI, and the spec and body of a package Cars. Cars_UI, in operation, looks something like this:
Select one of the operations below. C Clear the database R Read database from disk W Write database to disk A Add car to database D Delete car from database F Find a car in the database
P Display all records in the database Q Exit the program Please type a command, then press Enter > a Thank you for correct input. A entered; here we'd add
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 Cars_UI and run it, just to see how it behaves.
Step 2: Modify Simple_Dates according to the attached package spec. Use ideas and code from Project 7.
Step 3: Implement the following operations in Cars and tie them into Cars_UI:
ReadDatabase DisplayDatabase
We will provide a test data file cars.dat. You will be able to test these operations by running Cars_UI, entering an R command, then a P command.
Step 4: Now implement the operations
Put WriteDatabase AddCar
so you can read in the data, add a few AddCar transactions, then display and write the database to disk. You can then examine the disk file with vi or cat.
Step 5: Complete the other operations in the database package and tie them into Cars_UI.
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;