any help would b greatly appreciated for the following
how do i modify this to output the date in multiple formats:
a)DDD YYYY
MM/DD/YY
June 14, 1992
b) use overloaded constructors to create Date objects initialized with dates of the formats in part (a).
c) create a date constructor that reads the system date using the standard library functions of the <ctime> header and sets the Date members

#ifndef DATE_H
#define DATE_H
  class Date
  {
  public:
     Date( int = 1, int = 1, int = 1900 ); // default constructor
     void print() const; // print date in month/day/year format
     ~Date(); // provided to confirm destruction order
  private:
     int month; // 1-12 (January-December)
     int day; // 1-31 based on month
     int year; // any year

     // utility function to check if day is proper for month and year
    int checkDay( int ) const;
}; // end class Date

#endif

Recommended Answers

All 2 Replies

Here is a freebee for ye':

c) create a date constructor that reads the system date using the standard library functions of the <ctime> header and sets the Date members

class Date
{
     public:

     //Default constructor
     Date();

     private:

     //Date members
     struct tm* timeinfo;
     time_t rawtime;
     int day;
     int month;
     int year;    
};
Date::Date()
{
     time(&rawtime);
     timeinfo = localtime(&rawtime);

     day = timeinfo->tm_mday;
     month =  timeinfo->tm_mon;
     year =  timeinfo->tm_year + 1900;
}

http://www.cplusplus.com/reference/clibrary/ctime/

Here is a freebee for ye':

class Date
{
     public:

     //Default constructor
     Date();

     private:

     //Date members
     struct tm* timeinfo;
     time_t rawtime;
     int day;
     int month;
     int year;    
};
Date::Date()
{
     time(&rawtime);
     timeinfo = localtime(&rawtime);

     day = timeinfo->tm_mday;
     month =  timeinfo->tm_mon;
     year =  timeinfo->tm_year + 1900;
}

http://www.cplusplus.com/reference/clibrary/ctime/

thanks. i appreciate the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.