Question: 10.8 Case Study: A Date Class The program of Figs. 10.6 -10.8 _ demonstrates a Date class, which uses over- loaded prefix and postfix increment

10.8 Case Study: A Date Class The program of10.8 Case Study: A Date Class The program of10.8 Case Study: A Date Class The program of10.8 Case Study: A Date Class The program of
10.8 Case Study: A Date Class The program of Figs. 10.6 -10.8 _ demonstrates a Date class, which uses over- loaded prefix and postfix increment operators to add 1 to the day in a Date ob- ject, while causing appropriate increments to the month and year if necessary. The Date header (Fig. 10.6 2) specifies that Date's public interface includes an overloaded stream insertion operator (line 10), a default constructor (line 12), a setDate function (line 13), an overloaded prefix increment operator (line 14), an overloaded postfix increment operator (line 15), an overloaded += addition assignment operator (line 16), a function to test for leap years (line 17) and a func- tion to determine whether a day is the last day of the month (line 18). // Fig. 10.6: Date. h // Date class definition with overloaded increment operators. #ifndef DATE_H #define DATE_H ODD N G UA W N - #include #include class Date { friend std: :ostream& operator days; // days per month 25 void helpIncrement (); // utility function for incrementing date 26 27 28 #endif Fig. 10.6 Date class definition with overloaded increment operators.58 59 60 // add specified number of days to date 61 Date& Date: :operator+=(unsigned int additionalDays) { 62 for (unsigned int i = 0; i #include "Date.h" // Date class definition using namespace std; int main() { Date d1{12, 27, 2010}; // December 27, 2010 Date d2; // defaults to January 1, 1900 II cout #include #include "Date.h" using namespace std; // initialize static member; one classwide copy const array Date: : days{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Date constructor 13 Date: : Date (int month, int day, int year) { setDate (month, day, year); 15 16 17 // set month, day and year 18 void Date: : setDate(int mm, int dd, int yy) { 19 if (mm >= 1 && mm = 1900 && yy = 1900 and = 1 && dd = 1 && dd

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!