Question: Lab Exercise - Overloading Part 1 Change the sameDay function into a overloaded = = operator. This will be a member function as demonstrated in
Lab Exercise Overloading
Part
Change the sameDay function into a overloaded operator. This will be a member function as demonstrated in the notes. Remember that you will want to compare the month, day, and year.
Add an overloaded operator as a member function, shown in the notes
Just for fun, change the printDate function into an overloaded operator as a nonmember. The prototype in the h will look like this:
ostreams operatorostreamb const Dates;
The function itself will look like this:
Ostreams operatorostreams os const Dates myDate
os "Date s: myDate. getMonth
myDate.getDay
myDate. getYear endl;
return os;
Explain why operator must be overloaded as a nonmember.
Part
Overload the operator so that the following lines of code run in main:
More Details:
Define two functions. The prototypes will look like this:
Date operatort const Dates, int;
Date operatort int const Dates;
Are they member or nonmember functions? Notice how many arguments they have
Both functions will create a temporary date and return it
Think about reusing as much code as possible.
a For one implementation of operatort, can you call the operatort function?
b For the second implementation of operatort, can you call the first operator function?
c Together these two functions should be no more that lines of code in the bodies. If you make it longer, you are working too hard.
Which of the two functions must be defined as a nonmember? Why?
Sample Run after Part
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
