The George Washington University
School of Engineering and Applied Science
Department of Computer Science

CSci 51 -- Introduction to Computing -- Spring 2001

Project #6
Due Date: Start of Class, Tuesday, April 3, 2001

The purpose of this project is to give you some practice working with subtypes, exceptions, and exception handling.

Everything you need is in Chapters 1-7, and Section 11.2.

Background: In Project 4, you developed a package Date_Ops in which all your date validation and comparison was done "manually" with IF statements. As it happens, the standard library Ada.Calendar provides capabilities that make Date_Ops much simpler.

Part I:

To understand better how exception handling works, write a program, based on the one from Project 4, in which the acceptable year range is now the range of the subtype Ada.Calendar.Year_Number. This program will read, consecutively, a month number, a day number, and a year number. In each case, if the input is out of range or not an integer, the program will handle the relevant exception and prompt the user to try again. Once three valid values have been read, call Date_Ops.Is_Valid to determine whether the three values together constitute a valid date.

Part II:

Now develop a new date package, Date_Ops_2, based on Date_Ops, that uses Ada.Calendar features to validate and compare dates. Use ideas from Part I to develop the Get procedure. This package has the following specification:
WITH Ada.Calendar;
PACKAGE Date_Ops_2 IS
------------------------------------------------------------------------
--| Specification for package containing a few common date operations.
--| Author: Michael B. Feldman, The George Washington University
--| Last Modified: March 2001
------------------------------------------------------------------------
  FUNCTION IsValidDate 
             (Month: Ada.Calendar.Month_Number; 
              Day: Ada.Calendar.Day_Number; 
              Year: Ada.Calendar.Year_Number)
             RETURN Boolean;
  -- Pre:  Month, Day, and Year have well-defined values
  -- Post: returns True if the three parameters together 
  --       form a valid date
  FUNCTION IsEarlier
             (Month1: Ada.Calendar.Month_Number; 
              Day1: Ada.Calendar.Day_Number; 
              Year1: Ada.Calendar.Year_Number;
              Month2: Ada.Calendar.Month_Number; 
              Day2: Ada.Calendar.Day_Number; 
              Year2: Ada.Calendar.Year_Number)
             RETURN Boolean;
  -- Pre:  All six parameters have well-defined values, and each of the
  --       two sets of parameters forms a valid date
  -- Post: returns True if the date formed by Month1, Day1, Year1 is
  --       earlier than the date formed by Month2, Day2, Year2, and
  --       False otherwise
  PROCEDURE Get
             (Month: OUT Ada.Calendar.Month_Number; 
              Day: OUT Ada.Calendar.Day_Number; 
              Year: OUT Ada.Calendar.Year_Number);
  -- Pre:  None
  -- Post: Prompt user for values and validate them;
  --       Month, Day, and Year together form a valid date
END Date_Ops_2;
What to submit: See the document Preparation and Grading of Programming Projects for details. Your test plan and associated test program should include a proper set of tests for each of the two functions.