WITH Ada.Text_IO;
WITH Simple_Dates;
PACKAGE Compact IS
------------------------------------------------------------------
--| This package provides data structures and operations for
--| manipulating a simple "data base" of audio compact discs, each
--| record containing a code number, artist, disc title, category
--| of disc, date of purchase, and price you paid.
--|
--| The package makes use of resources provided
--| by the package Simple_Dates.
--|
--| Author: Michael B. Feldman, The George Washington University
--| Last Modified: March 1997
------------------------------------------------------------------
-- constant and type definitions
NameSize: CONSTANT Positive := 10;
MaxDiscs: CONSTANT Positive := 25;
SUBTYPE BarCode IS Positive RANGE 00001..99999;
SUBTYPE NameType IS String(1..NameSize);
SUBTYPE PriceType IS Float RANGE 0.00 .. 99.99;
TYPE Categories IS (Jazz, Rock, Classical, Comedy);
TYPE Disc IS PRIVATE;
-- operations
PROCEDURE Get (Item: OUT Disc);
-- Pre: None
-- Post: Gets a disc record, robustly, from the keyboard
PROCEDURE Put (Item: IN Disc);
-- Pre: Item is defined
-- Post: Displays one disc record on the screen
PROCEDURE DisplayDatabase;
-- Pre: The database has at least been cleared
-- Post: Displays the entire database on the screen
PROCEDURE ClearDatabase;
-- Pre: None
-- Post: The database behaves as though it is empty
PROCEDURE ReadDatabase;
-- Pre: None
-- Post: Reads all records from a file into the database
PROCEDURE WriteDatabase;
-- Pre: The database has at least been cleared
-- Post: Writes all records in the database to a file
PROCEDURE FindDisc(Code: IN BarCode;
Item: OUT Disc; Success: OUT Boolean);
-- Pre: Code is defined
-- Post: If this disc is already in the database, returns the
-- disc record and Success is True;
-- otherwise, Success is False
PROCEDURE AddDisc (Item: IN Disc; Success: OUT Boolean);
-- Pre: Item is defined
-- Post: If this disc is not already in the database, adds this
-- disc to the database and Success is True;
-- otherwise, Success is False
PROCEDURE DeleteDisc (Code: IN BarCode; Success: OUT Boolean);
-- Pre: Tag is defined
-- Post: If this disc is already in the database, deletes this
-- disc from the database and Success is True;
-- otherwise, Success is False
PRIVATE
TYPE Disc IS RECORD
CodeNumber: BarCode;
Artist: NameType;
Title: NameType;
Category: Categories;
PurchaseDate: Simple_Dates.Date;
PurchasePrice: PriceType;
END RECORD;
END Compact;