package Currency is
------------------------------------------------------------------
--|                                                              
--| Specification of the abstract data type for representing
--| and manipulating Currency numbers.
--| All values of type Currency.Quantity are initialized to 0.0.
--|                                                              
--| Author: Michael B. Feldman, The George Washington University 
--| Last Modified: July 1995                                     
--|                                                              
------------------------------------------------------------------

  subtype CentsType is Integer range 0..99;
  type    Quantity  is private;

  -- Operations 

  function MakeCurrency (F : Float)    return Quantity;
  -- constructor:
  -- Pre : F is defined
  -- Post: returns a Currency Quantity

  function MakeFloat    (Q : Quantity) return Float;
  -- constructor:
  -- Pre:  Q is defined
  -- Post: returns the value of Q in Float form
  
  function Dollars   (Q : Quantity) return Natural;
  function Cents     (Q : Quantity) return CentsType;
  function IsPositive(Q : Quantity) return Boolean;
  -- selectors:
  -- Pre:  Q is defined
  -- Post: Dollars returns the Dollars part of Q; Cents the Cents part
    
  function "<" (Q1 : Quantity; Q2 : Quantity) return Boolean;
  function ">" (Q1 : Quantity; Q2 : Quantity) return Boolean;
  function "<="(Q1 : Quantity; Q2 : Quantity) return Boolean;
  function ">="(Q1 : Quantity; Q2 : Quantity) return Boolean;
  -- inquiry operators:
  -- Pre : Q1 and Q2 are defined
  -- Post: return Q1 < Q2, Q1 > Q2, Q1 <= Q2, and Q1 >= Q2, respectively
   
  function "+"  (Q  : Quantity) return Quantity;
  function "-"  (Q  : Quantity) return Quantity;
  function "abs"(Q  : Quantity) return Quantity;
  -- monadic arithmetic constructors:
  -- Pre:  Q is defined
  -- Post: return Q, -Q, ABS Q respectively
  
  function "+"  (Q1 : Quantity; Q2 : Quantity) return Quantity;
  function "-"  (Q1 : Quantity; Q2 : Quantity) return Quantity;
  function "*"  (F  : Float;    Q  : Quantity) return Quantity;
  function "*"  (Q  : Quantity; F  : Float   ) return Quantity;
  function "/"  (Q1 : Quantity; Q2 : Quantity) return Float;
  function "/"  (Q  : Quantity; F  : Float   ) return Quantity;
  -- dyadic arithmetic constructors:
  -- Pre : Q1 and Q2 are defined
  -- Post: these are the sensible arithmetic operators on Quantity.
  --   Note that multiplying two monetary values is not sensible.

private

-- A record of type Quantity consists of a pair of Natural values
-- such that the first number represents the Dollars part
-- and the second number represents the Cents part.
-- The sign of a Quantity value is indicated by a Boolean field
-- called Positive.

  type Quantity is record
    Positive: Boolean   := True;
    Dollars : Natural   := 0;
    Cents   : CentsType := 0;
  end record; -- Quantity

end Currency;