Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++: Consider the definition of the class dateType given in Chapter 11. a) Write

ID: 3752810 • Letter: C

Question

C++: Consider the definition of the class dateType given in Chapter 11.

a) Write the statement that includes a friend function named before in the class dateType that takes as parameters two objects of type dateType and returns true if the date represented by the first object comes before the date represented by the second object; otherwise, the function returns false.

b) Write the definition of the function you defined in part a.

Here is the class that is given:

class dateType
{
public:
void setDate(int month, int day, int year);
int getDay() const;
int getMonth() const;
int getYear() const;
void printDate() const;
dateType(int month = 1, int day = 1, int year = 1900);

private:
int dMonth;
int dDay;
int dYear;
};

I am not good with friend functions so any help you could offer would be much apperciated.

Thank you in advance

Explanation / Answer

friend bool before(dateType &d1, dateType &d2){ // check if years are different, then which is earlier if(d1.getYear() d1.getYear()) { return -1; } // if years are same, check months if(d1.getMonth() d1.getMonth()) { return -1; } // if year and months are same, check days if(d1.getDay() d1.getDay()) { return -1; } // both dates are same return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote