// datum.cc #include // ostream #include // ifstream #include "datum.hh" //-------------------------------------------------------------------- // Default Constructor Datum :: Datum() { day_ = month_ = year_ = 0; } //-------------------------------------------------------------------- // Parameter Constructor Datum :: Datum(const unsigned short day, const unsigned short month, const unsigned short year) { day_ = day; month_ = month; year_ = year; } //-------------------------------------------------------------------- // Copy Constructor Datum :: Datum(const Datum &orig) { day_ = orig.day_; month_ = orig.month_; year_ = orig.year_; } //-------------------------------------------------------------------- // Constructor via file (Ü6B) Datum :: Datum(const char filename[]) { ifstream infile(filename); // No check whether file exists ==> more to do infile >> day_ >> month_ >> year_; } //-------------------------------------------------------------------- // Destructor Datum :: ~Datum() {} // nothing to do //-------------------------------------------------------------------- // Assignment operator Datum& Datum :: operator = (const Datum &orig) { // if ( &orig != this ) - test nicht notwendig, da keine dynamischen Datzen in der Klasse sind day_ = orig.day_; month_ = orig.month_; year_ = orig.year_; return *this; } //-------------------------------------------------------------------- // Comparison operator (earlier) bool Datum :: operator < (const Datum &orig) const { bool bb; if ( year_ != orig.year_ ) { bb = ( year_ < orig.year_ ); } else if ( month_ != orig.month_ ) // Gleiches Jahr ==> weiter mit Monat { bb = ( month_ < orig.month_ ); } else if ( day_ != orig.day_ ) // Gleicher Monat ==> weiter mit Tag { bb = ( day_ < orig.day_ ); } else // bleibt bloss noch gleicher Geburtstag uebrig { bb = false; } return bb; } //-------------------------------------------------------------------- // Comparison operator (equal) bool Datum :: operator == (const Datum &orig) const { return ( year_ == orig.year_ && month_ == orig.month_ && day_ == orig.day_); } //-------------------------------------------------------------------- // Print operator ostream & operator<<(ostream & s, const Datum & orig) { s << orig.day_ << ". " << orig.month_ << ". " << orig.year_; return s; }