P31 Given the following date class interface class date priv
P3.1 Given the following date class interface: class date private: int month 1-12 int day; 1 28, 29, 30, 31 depending on month & year int year: 4-digit, e.g., 2017 public date() Default constructor (investigate; find what it is used for) Postcondition: the newly declared date object is initialized to 01/01/2000 date(int mm. int dd, int yyyy); Second constructor Postcondition: the newly declared data object is initialized to void setDate(int mm, int dd, int yyyy); Postcondition: set the contents of the calling date object to the values passed to the function void displayDateV10; Postcondition: display the calling date object in mm/ddy format, e.g., 02/22/2017 void displayDatev20; Postcondition: display the calling datecobject in the format like: February 22, 2017 int compare Dates date &dobj;); compares the two date objects: the calling one the dObj that is passed to the function Postcondition: returns -1, 0, or 1 if the calling date object if less than, equal to, or greater than dobj, respectively. Your are asked to Implement all six member functions Write a main0 function containing C++ code to test all six member functions. Note that for the compareDates function, you must test all three possibilities! Format you program output so make it easily readable
Solution
Answer:
Below is the code where Class has been replaced by struct
struct date{
int month;
int day;
int year;
}date1;
void date()
{
date1->month = 01;
date1->day = 01;
date1->year = 1991;
}
void date (int mm, int dd, int yyyy)
{
date1->month = mm;
date1->day = dd;
date1->year = yyyy;
}
void setDate (int mm, int dd, int yyyy)
{
date1->month = mm;
date1->day = dd;
date1->year = yyyy;
}
void displayDateV1()
{
printf(\"%d/%d/%d\",date1->month,date1->day,date1->year);
}
int main()
{
date();
date(2,7,1996);
setDate(2,7,1996);
displayDateV1();
}
