/** Time.h -----------------------------------------------------------
 This header file defines the data type Time for processing time.
 Basic operations are:
   Set:     To set the time
   Display: To display the time 
----------------------------------------------------------------------*/

#include <iostream>
using namespace std;

class Time
{
/******** Member functions ********/
public:

/***** Class constructors *****/

/* --- Construct a class object (default).
 *  Precondition:  A Time object has been declared.
 *  Postcondition: The Time object is initialized to 12:00 A.M.; 
 *                 that is, the myHours, myMinutes, and myAMorPM 
 *                 members are initialized to 12, 0, 'A', respectively,
 *                 and myMilTime to 0.
 **********************************************************************/

Time();

/* --- Construct a class object (explicit values).
 *  Precondition:  A Time object has been declared.
 *  Receive:       Initial values initHours, initMinutes, and 
 *                 initAMPM
 *  Postcondition: The myHours, myMinutes, and myAMorPM members 
 *                 of theTime object are initialized to initHours, 
 *                 initMinutes, and initAMPM , respectively, and 
 *                 myMilTime to the corresponding military time.
 **********************************************************************/

Time(unsigned initHours, unsigned initMinutes, char initAMPM);

/* Set sets the data members of a Time object to specified values.
 *
 *  Receive:  hours, the number of hours in standard time
 *            minutes, the number of minutes in standard time
 *            AMPM ('A' if AM, 'P' if PM
 *  Return:   The Time object containing this function with its
 *            myHours, myMinutes, and myAMorPM members set to hours,
 *            minutes, and am_pm, respectively, and myMilTime to
 *            the equivalent military time
 ********************************************************************/

void Set(unsigned hours, unsigned minutes, char am_pm);

 
/***** Data Retrievers *****/

/* Hour Accessor
 *  Receive: The Time object containing this function (implicitly)
 *  Return:  The value stored in the myHours member of the Time
 *           object containing this function
 *****************************************************************/

unsigned Hour() const;

// and similar functions for myMinutes, 
// myAMorPM, and myMilTime retrieval

/***** I/O Functions *****/
/* operator<< displays time in standard and military format
 * using ostream out.
 *  Receives:     An ostream out and a Time object t
 *  Output:       The time represented by the Time object containing 
 *                this function
 *  Passes back:  The ostream out with t inserted into it.
 *  Return value: out
 ********************************************************************/

friend ostream & operator<<(ostream & out, const Time & t);

/* --- operator>> inputs a Time value from istream in.
 *
 *  Receives:     An istream in and a Time object t
 *  Input :       Values for the data members of t.
 *  Passes back:  The istream in with values removed from it
 *                t with values stored in its data members
 *  Return value: in
 *  Note:  Times are input in the format hh:mm xM
 ****************************************************************/

friend istream & operator>>(istream & in, Time & t);

/***** Relational operators *****/

/* --- operator< determines if the current Time object is less 
 *     than another Time object
 *
 *  Receive: Time t and the Time object containing this 
 *             function (implicitly)
 *  Return:  true if the Time object containing this function 
 *             is less than t; false otherwise
 ***************************************************************/

bool operator<(const Time & t) const;

/***** Increment operator *****/

/* --- Advance() increments a Time by a specified value.
 *
 *  Receive:  hours, the number of hours to add
 *            minutes, the number of minutes to add
 *  Return:   The Time object containing this function with its 
 *            data members incremented by these values
 *****************************************************************/

void Advance(unsigned hours, unsigned minutes);


/********** Data Members **********/
private:
   unsigned myHours,
            myMinutes;
   char myAMorPM;        // 'A' or 'P'
   unsigned myMilTime;   // military time equivalent

}; // end of class declaration

//----- Definition of default constructor
inline Time::Time()
{
  myHours = 12;
  myMinutes = 0;
  myAMorPM = 'A';
  myMilTime = 0;
}

//----- Definition of Hour()
inline unsigned Time::Hour() const
{ return myHours; }

//----- Definition of operator<
inline bool Time::operator<(const Time & t) const
{ return myMilTime < t.myMilTime; }

