WITH Ada.Text_IO;
WITH Simple_Dates;
PACKAGE Cars IS
------------------------------------------------------------------
--| This package provides data structures and operations for
--| manipulating a simple "data base" of car records, each
--| record containing a tag number, car make, date of purchase
--| and owner's name.
--| The package makes use of resources provided
--| by the package Simple_Dates.
--|
--| Author : Michael B. Feldman, The George Washington University
--| Changed : Chester B. Lund, The George Washington University
--|
--| Last Modified: September 1998
------------------------------------------------------------------
--|
--| The user interface menu is as follows:
--|
--| 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 >
-----------------------------------------------------------------
NameSize : CONSTANT Positive := 10; -- CONSTANTS Defined
MaxCars : CONSTANT Positive := 30;
SUBTYPE NameType IS String (1..NameSize); -- SUBTYPES Defined
SUBTYPE CarRange IS Natural RANGE 0..MaxCars;
SUBTYPE CarIndex IS Natural RANGE 1..MaxCars;
SUBTYPE TagType IS Positive RANGE 000001..777777;
TYPE Makes IS (Ford, Chevrolet, Honda, Subaru); -- CARS TYPES Defines
TYPE Car IS RECORD -- CAR Record Defined
TagNumber: TagType;
Make: Makes;
PurchaseDate: Simple_Dates.Date;
Owner: NameType;
END RECORD;
TYPE DatabaseType IS ARRAY(CarIndex) OF Car; -- TYPE is ARRAY of RECORDS
-- "abstract data object" for the car database -- Pending database table
DB_Pending : DatabaseType; -- Car database -> Pending
CT_Pending : CarRange; -- Count of rows in Pending
-- "abstract data object" for the car database -- Commit database table
DB_Commit : DatabaseType; -- Car database -> Commit
CT_Commit : CarRange; -- Count of rows in Commit
-- Operations (they are all PROCEDURES)
PROCEDURE Get (Item: OUT Car);
-- Pre: None
-- Post: Gets a car record, robustly, from the keyboard
PROCEDURE Put (Item: IN Car);
-- Pre: Item is defined
-- Post: Displays one car record on the screen
PROCEDURE Commit_Database; -- C -> Table, Commit Table
-- Pre: None
-- Post: DB_Pending is copied DB_Commit
-- DB_Commit is the database version that is written
PROCEDURE Rollback_Database; -- R -> Table, Rollback Table
-- Pre: None
-- Post: DB_Commit is copied back to DB_Pending
-- All pending actions (add, update, or delete) are lost
PROCEDURE Select_Database; -- S -> Table, Select all Rows
-- Pre: The database has at least been cleared
-- Post: Displays the entire database on the screen
PROCEDURE Truncate_Database; -- T -> Table, Truncate Table
-- Pre: None
-- Post: DB_Pending database behaves as though it is empty
PROCEDURE Add_Row -- A -> Row, Add One Row
(Item: IN Car; Success: OUT Boolean);
-- Pre: Item is defined
-- Post: If this car is not already in the database, adds this
-- car to the database and Success is True;
-- otherwise, Success is False
PROCEDURE Delete_Row -- D -> Row, Delete One Row
(Tag: IN TagType; Success: OUT Boolean);
-- Pre: Tag is defined
-- Post: If this car is already in the database, deletes this
-- car from the database and Success is True;
-- otherwise, Success is False
PROCEDURE Find_Row -- F -> Row, Find a Row
(Tag: IN TagType; Item: OUT Car; Success: OUT Boolean);
-- Pre: Tag is defined
-- Post: If this car is already in the database, returns the
-- car record and Success is True;
-- otherwise, Success is False
PROCEDURE Update_Row -- U -> Row, Update One Row
(Tag: IN TagType; Item: IN Car; Success: OUT Boolean);
-- Pre: Tag is defined
-- Post: If this car is already in the database, returns the
-- updated car record and Success is True;
-- otherwise, Success is False
END Cars;