// time.cc P. Conrad CISC181 Spring 2005

#include "time.h"
#include <iostream>
#include <iomanip> // for setfill and setw
  
// note: out is a reference (alias) for, for example, cout or cerr
// the type is "ostream &" (ostream reference)

void Time_C::print(std::ostream &out) const
{ 
  // Print the hour. Use mod 12 to convert pm times. Print 12 instead of 0  
  out <<  ( ( hour%12==0 ) ? 12 : (hour%12) ); 
  // print ":" then the minute, zero filled in width of two.
  out << ":" << std::setfill('0') << std::setw(2) << min << std::setfill(' '); 
  // print either am or pm  Noon prints as 12:00pm
  out << ( (hour<12) ? "am" : "pm" ); 
}
	
std::ostream & operator << (std::ostream & left, const Time_C & right)
{
  right.print(left);
  return left;
}



