--Date: December, 2000 --Author: R. McCloskey --Description: specification of a package for the Bowling Frame ADT package Bowling_Frames is type Frame_Type is private; Num_Pins : constant Natural := 10; --number of pins in a rack subtype Pin_Cnt_Range is --range of pins that can Natural range 0..Num_Pins; --be felled in a frame subtype Throw_Range is Positive range 1..2; --range of throws in a frame Bad_Pin_Cnts, Bad_Throw_Num : exception; --<<<< c o n s t r u c t o r s >>>> function Create( Throws : Throw_Range := 2; Pins_1 : Pin_Cnt_Range; Pins_2 : Pin_Cnt_Range := 0) return Frame_Type; --------------------------------------------------------------------- --pre: Pins_1 + Pins_2 <= Num_Pins and -- Throws = 1 implies Pins_2 = 0 --post: Let F be the Frame returned by this function; -- then Num_Throws(F) = Throws and -- Pin_Count(F,1) = Pins_1 and -- (assuming Throws = 2) Pin_Count(F,2) = Pins_2 --excep: Bad_Pin_Cnts is raised if precondition not met --note: Throws and Pins_2 are optional parameters that, if not -- specified by the caller, take on the specified default -- values. --------------------------------------------------------------------- procedure Create( Frame : out Frame_Type; Throws : in Throw_Range := 2; Pins_1 : in Pin_Cnt_Range; Pins_2 : in Pin_Cnt_Range := 0); --------------------------------------------------------------------- --pre: same as function Create above --post: Frame satisfies same conditions as the above function's -- return value (called F in the comments above) --excep: same as function Create above --note: same as function Create above --------------------------------------------------------------------- --<<<< o b s e r v e r s >>>> function Num_Throws( Frame : Frame_Type ) return Throw_Range; ------------------------------------------------------------ --pre: none --post: returns number of throws made in Frame ------------------------------------------------------------ function Pin_Count( Frame : Frame_Type; Throw : Throw_Range ) return Pin_Cnt_Range; ------------------------------------------------------------ --pre: Throw <= Num_Throws(Frame) --post: returns pin count of the Throw-th throw in Frame --excep: Bad_Throw_Num raised if precondition not met ------------------------------------------------------------ function Is_Strike( Frame : Frame_Type ) return Boolean; ------------------------------------------------------- --pre: none --post: returns true if Frame corresponds to a strike -- (i.e., all pins were knocked down on 1st throw); -- returns false otherwise ------------------------------------------------------- function Is_Spare( Frame : Frame_Type ) return Boolean; ------------------------------------------------------ --pre: none --post: returns true if Frame corresponds to a spare -- (i.e., all pins were knocked down in two throws); -- returns false otherwise ------------------------------------------------------ function Is_Open( Frame : Frame_Type ) return Boolean; ------------------------------------------------------ --pre: none --post: returns true if Frame is open (neither strike -- nor spare); returns false otherwise ------------------------------------------------------ --<<<< p r i v a t e >>>> --Note: private part of specification is "invisible" to clients private type Frame_Type is record Numb_Throws : Throw_Range := 2; --throws made in frame Pin_Cnt_1 : Pin_Cnt_Range := 0; --# pins knocked down on 1st throw Pin_Cnt_2 : Pin_Cnt_Range := 0; --# pins knocked down on 2nd throw end record; end Bowling_Frames;