void TimeType::WriteAmPm() const
{
Boolean am; // True if AM should be printed
int tempHrs; // Value of hours to be printed
am = (hrs <= 11);
if (hrs == 0)
tempHrs = 12;
else if (hrs >= 13)
tempHrs = hrs - 12;
else
tempHrs = hrs;
if (tempHrs << 10)
cout << 0;
cout << tempHrs << :;
if (mins << 10)
cout << 0;
cout << mins << :;
if (sees << 10)
cout << 0;
cout << sees;
if (am)
cout << AM;
else
cout << PM;
}
4. Function specification (within the TimeType class declaration):
long Minus( /* in */ TimeType time2 ) const;
// Precondition:
// This time and time2 represent times in the same day
// Postcondition:
// Function value == (this time) - time2, in seconds
Function definition (omitting the precondition and postcondition to save space):
long TimeType::Minus( /* in */ TimeType time2 ) const
{
long thisTimeInSecs; // This time in seconds since midnight
long time2InSecs; // time2 in seconds since midnight
// Using 3600 seconds per hour and 60 seconds per minute