Time Class Reference

List of all members.

Public Member Functions

 Time ()
 Time (const int newHours, const int newMinutes)
int getHours () const
int getMinutes () const
void setHours (const int newHours)
void setMinutes (const int newMinutes)
void print (ostream &out=cout) const
void println (ostream &out=cout) const
void enter (istream &in=cin)
void read (istream &in)
void write (ostream &out) const
void add (const Time &time)
bool equal (const Time &time) const
bool lessThan (const Time &time) const
void operator+= (const Time &time)
bool operator== (const Time &time) const
bool operator< (const Time &time) const

Static Public Attributes

static const int maxHours = 24
static const int maxMinutes = 60
static const Time noon

Friends

ostream & operator<< (ostream &out, const Time &time)
istream & operator>> (istream &in, Time &time)

Detailed Description

A class for storing information about time in military format.

Author:
Mark Maloof (maloof@cs.georgetown.edu)
Version:
1.0, 8/16/13

Constructor & Destructor Documentation

Time::Time (  ) 

Default constructor. Sets this time object to 00:00.

Time::Time ( const int  newHours,
const int  newMinutes 
)

Explicit constructor. Sets this time object to the specified hours and minutes. Out-of-range values will not replace default values.

Parameters:
newHours the hours of this time object
newMinutes the minutes of this time object

Member Function Documentation

void Time::add ( const Time time  ) 

Adds the specified time object to this time object.

Parameters:
time the time object to be added
void Time::enter ( istream &  in = cin  ) 

Extracts a time in the format "hh:mm" from the specified input stream. If there are problems with the format of the information in the stream, then no values are set. Out-of-range values do not replace current values.

Parameters:
in the input stream for reading
bool Time::equal ( const Time time  )  const

Returns true if this time object is equal to the specified time object; returns false otherwise.

Parameters:
time the time object to be compared
Returns:
true if the objects are equal
int Time::getHours (  )  const

Returns the hours of this time object.

Returns:
the hours
int Time::getMinutes (  )  const

Returns the minutes of this time object.

Returns:
the minutes
bool Time::lessThan ( const Time time  )  const

Returns true if this time object is less than the specified time object; returns false otherwise.

Parameters:
time the time object to be compared
Returns:
true if this object is less than the specified object
void Time::operator+= ( const Time time  ) 

Adds the specified time object to this time object.

Parameters:
time the time object to be added
bool Time::operator< ( const Time time  )  const

Returns true if this time object is less than the specified time object; returns false otherwise.

Parameters:
time the time object to be compared
Returns:
true if this object is less than the specified object
bool Time::operator== ( const Time time  )  const

Returns true if this time object is equal to the specified time object; returns false otherwise.

Parameters:
time the time object to be compared
Returns:
true if the objects are equal
void Time::print ( ostream &  out = cout  )  const

Prints this time object to the specified output stream in the format "hh:mm" with no terminating end-of-line character.

Parameters:
out the output stream for printing
void Time::println ( ostream &  out = cout  )  const

Prints this time object to the specified output stream in the format "hh:mm" with a terminating end-of-line character.

Parameters:
out the output stream for printing
void Time::read ( istream &  in  ) 

Reads a time in the format "hh mm" from the specified input stream. If there are problems with the format of the information in the stream, then no values are set. Out-of-range values do not replace current values.

Parameters:
in the specified input stream for reading
void Time::setHours ( const int  newHours  ) 

Sets the hours of this object to the specified hours, which must be in {0,..., 23}. Out-of-range values do not replace current values.

Parameters:
newHours the specified hours
void Time::setMinutes ( const int  newMinutes  ) 

Sets the minutes of this object to the specified minutes, which must be in {0,..., 59}. Out-of-range values do not replace current values.

Parameters:
newMinutes the specified minutes
void Time::write ( ostream &  out  )  const

Writes this time object to the specified output stream in the format "hh mm" with no terminating end-of-line character.

Parameters:
out the output stream for writing

Member Data Documentation

const int Time::maxHours = 24 [static]

the maximum value for hours

const int Time::maxMinutes = 60 [static]

the maximum value for minutes

const Time Time::noon [static]

a constant for noon


The documentation for this class was generated from the following file:
 All Classes Functions Variables

Generated on 15 Nov 2013 by  doxygen 1.6.1